Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Day for the given Date in Java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Aghil krishna
Day for the given Date in Java
4 Answer(s)      4 years ago
Posted in : Java Beginners


How can i get the day for the user input data ?


Advertisement
View Answers

November 10, 2010 at 2:41 PM


Hello Friend,

You can use the following code:

import java.util.*;
import java.text.*;
class  CheckDay{
   public static void main(String[] args){
     Scanner input=new Scanner(System.in);
     System.out.println("Enter date(1-31):");
     int dd=input.nextInt();
     System.out.println("Enter month(1-12): ");
     int month=input.nextInt()-1;
     System.out.println("Enter year: ");
     int year=input.nextInt();
   Date date= (new GregorianCalendar(year, month, dd)).getTime();
   SimpleDateFormat f = new SimpleDateFormat("EEEE");
     String day=f.format(date);
     System.out.println(day);
     }
}

Thanks



January 20, 2012 at 9:17 PM


thank you for the program.... it was very useful to me...but how can i find a day without using the SimpleDateFormat class..



March 5, 2012 at 3:42 PM


 By Nishanth Thomas  - Insolutions Global  Bangalore

  package example;

     import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;

   import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;

public class test3 {

/**
 * @param args
 * @throws java.text.ParseException 
 */
 public static void main(String[] args) throws java.text.ParseException {
    // TODO Auto-generated method stub
    try {  
     String str_date="11-jan-07";
     DateFormat formatter ; 
      Date date ; 
      formatter = new SimpleDateFormat("dd-MMM-yy");
      date = (Date)formatter.parse(str_date);  
    // System.out.println("Today is " +date );

     SimpleDateFormat sdf;

     sdf = new SimpleDateFormat("DD/MM/yyyy");
     System.out.println("DAte " + sdf.format(date));


      } catch (ParseException e)
      {
          System.out.println("Exception :"+e);  }  

     }
    }


March 5, 2012 at 4:37 PM


Convert into format 23/08/2007 if given date is 23/08/2007 or 23-aug-2010

 By Nishanth Thomas  - Insolutions Global  Bangalore
  package example;

  import java.text.DateFormat;
  import java.text.SimpleDateFormat;
 import java.util.Date;

 import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;

public class test3 {

/**
 * @param args
 * @throws java.text.ParseException 
 */
public static void main(String[] args) throws java.text.ParseException {
    // TODO Auto-generated method stub

        String str_date="23/08/2007";  // or 23-aug-2010

        DateFormat formatter ; 
        Date date ; 
        SimpleDateFormat sdf = null;
        try{
            formatter = new SimpleDateFormat("dd/MM/yyyy");
            date = (Date)formatter.parse(str_date);
            //System.out.println(formatter);

            sdf = new SimpleDateFormat("dd/MM/yyyy");
            System.out.println("DAte " + sdf.format(date));

        }catch (Exception e){
            //  e.printStackTrace();
              System.out.println(" error");
            try{
                formatter = new SimpleDateFormat("dd-MMM-yyyy");
                date = (Date)formatter.parse(str_date);  
            //  System.out.println("Today is " +date );



                sdf = new SimpleDateFormat("dd/MM/yyyy");
                System.out.println("DAte " + sdf.format(date));



            } catch (ParseException e1)
            {
                System.out.println("Exception :"+e1);  
                }  


        }
 }

}



Related Tutorials/Questions & Answers:
Day for the given Date in Java
Day for the given Date in Java  How can i get the day for the user..."); String day=f.format(date); System.out.println(day...("Enter date(1-31):"); int dd=input.nextInt(); System.out.println("Enter
is this programm efficient to find the day of the given date . can it be more normalized ?
is this programm efficient to find the day of the given date . can it be more normalized ?  #include <stdio.h> int main(void) { int dd...; total = total %7; printf("%d\n",total); printf("the day is %s",week
Advertisements
Java date add day
Java date add day In this tutorial, you will learn how to add days to date... to date or subtract days from date) for java applications. Here, we are going to add few days to current date and return the date of that day. For this, we
how to find the given date is sunday
how to find the given date is sunday  how to find the given date is sunday in java?   Hi Friend, Try the following code: import...[] args){ Date date= (new GregorianCalendar(2010, Calendar.SEPTEMBER, 20)).getTime
Determining the Day-of-Week for a Particular Date
Determining the Day-of-Week for a Particular Date       This section simply show the current day in word i.e. the Day of Week for a particular date. Here, you can learn about the way
PHP Date add 1 day
PHP Date add 1 day This simple code will tell you how you can easily add 1 day to a date.  Example code for PHP Date add 1 day: <?php...;.$todayDate."<br>"; //Add one day to today $date = strtotime(date
how to find last day 0f any given month in mysql?
how to find last day 0f any given month in mysql?  how to find last day of any given month in mysql?   Hi Friend, Here is required code: DECLARE @dtDate DATETIME SET @dtDate = '8/18/2007' SELECT DATEADD(s,-1,DATEADD
date_sunset
date_sunset() in PHP date_sunset function returns the sunset time for a given day and location. The day is specified as a timestamp. It returns the sunset... of date_sunset() in PHP timestamp - The timestamp of the day from which
Java get Next Day
Java get Next Day       In this section, you will study how to get the next day in java using Calendar class. In the given example, we have used the class
Getting Previous, Current and Next Day Date
Getting Previous, Current and Next Day Date   ... previous, current and next date in java. The java util package provides... the previous, current and next date to Date() constructor of java.util package
Find the Day of the Week
Find the Day of the Week       This example finds the specified date of  an year and a day... Object class and converts a Date object into a set of integer fields. Calendar
java code for given query
java code for given query  i am not able to display to display graph in all browsers it is only displaying in ie using java
Get first day of week
; week in Java. As we know that GregorianCalendar provides the current date, month..._package>java FirstDayOfWeek Day of week: 7 Sunday... Get first day of week      
Display Date - Java Beginners
Display Date  Plz send me sample java program that display day, date... to display day,date,year and current time. import java.util.*; class DateExample { public static void main(String[] args) { Date date = new Date
Mysql Date Minus Days
subtracting 2 day from current date:- The given below Query return you the date after subtracting 2 day from current date.  mysql> select...; The Tutorial cover on Mysql Date Minus Days return you the day after
Date Java - Java Beginners
: public class Date { private int month; // 1-12 private int day; // 1-31... for day. public Date( int theMonth, int theDay, int theYear ) { if ( theMonth... ); // validate day System.out.println("Date object constructor for date
Java Get Month from Date
Java Get Month from Date     ... month from the current date using Java Application Language.  You can see... of framework classes and utilities with date and time facilities in Java
Get Last Day of The Month
for this field, given the current date and store its value int variable max day... and a set of integer fields such as YEAR, MONTH, DAY, HOUR.. A Date object ... Get Last Day of The Month     
java Date - Java Beginners
java Date  Dear sir I have an assignment, It is .. "Develop Date...; private final int day; private final int year; public Date(int m, int d...; return (y % 4 == 0); } public Date next() { if (isValid(month, day + 1
program on factorial of a given number in java
program on factorial of a given number in java  please tell me, how to write program on factorial of a given number in java
program on factorial of a given number in java
program on factorial of a given number in java  please tell me, how to write program on factorial of a given number in java
Find Day of Month
Find Day of Month       This example explores how to find the day of a month and the day of a week  This example sets the year as 2007 and the day as 181. The example 
date problem - Java Beginners
date problem  how to extract day,month,year hours ,second from a string date. Examples: String dat ="200912202934" from this string extract month ,year,date,hours,minute Please help me. Thanks in advance Sushil 
Toedter JDateChooser JSpinner change day value by default in java
Toedter JDateChooser JSpinner change day value by default in java  i have a question, by default the JSpinner when you press up or down buttons it changes the month value. There is a way to change the day value, instead
Java Date conversion - Date Calendar
Java Date conversion  How do I convert 'Mon Mar 28 00:00:00 IST 1983' which is a java.util.Date or String to yyyy/MM/dd date format in sql
Java Date Class
Java Date Class  Hi Friend, I need to have a code to get the days..., the days would be saturday, sunday and monday, the code I gave simply get one day... userIn = new Scanner(System.in); int dates, day, dayOfMonth, month, century, year
Java Script Code of Calendar and Date Picker or Popup Calendar
Java Script Code of Calendar and Date Picker or Popup Calendar...; This is detailed java script code that can use for Calendar or date picker or popup... selected date from the date picker.  2: calendar.js: Java script code file
Java: Some problems in given condition
Java: Some problems in given condition   SIR, I want to get the values from the table( database), if any one of the column of the table value is 0. Then one alert should b printed in application using Java. If(att.getdata1()==0
java yesterday - Date Calendar
java yesterday  Afternoon,Yesterday i have a question that how to make date sustract, the result is to make 1 month and 1 day like this, right. now...; } if(cur_date > date){ day = cur_date - date; }else{ day = cur
Java Increment Date. - Java Beginners
Java Increment Date.  Create a program called Date.java to perform.... Also, provide a method nextDay() to increment the day by one. The Date object... have so far: public class Date { private int day; // 1-31
Output Previous or Next Day of the Month
or previous day: The program should output the next day's or previous day's date... the next day of the 30th If bad input is given, then each of them should have... sequence of: Enter todays date(1-30): 30 Do you want the next or previous day
 

 

 

DMCA.com