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

 
 


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

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

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 Pages:
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
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
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
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 
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
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
DATE
the date of all the thursdays of the given year. import java.util.*; import...DATE  I have the following as my known parameter Effective Date : 21-08-2012 Cut off day : Thursday every week I want my first cycle calculation done
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 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
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      
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
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
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
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
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
Java get yesterday's date
Java get yesterday's date   ... the yesterday's date.  In the given example, we simply get the current date by using the method dateFormat.format(cal.getTime()).But on subtracting one day from
Date Formay - Date Calendar
in java.  Hi friend, Code to compare two different date import...(currentcal.getTime()) + ") is greater than the given date " + new SimpleDateFormat...(currentcal.getTime()) + ") is less than the given date " + new
Current Date iPhone SDK
date & day in iPhone SDK. We'll also write a method to print the day and date...;]; In this example, we aims to print the current day, current Date and first weekend day of the same week. Just copy and paste the given code into your
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
date_parse
date_parse() in PHP date_parse function returns associative array with detailed information about given date. It returns information about the date on success, or FALSE on failure. An error message will display if date format faces any
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
Simple Date example
. Parameterized constructor :- Date(int year,int month,int day) creates a Date object and initialize it with given year+1900,  given month and given day. Date newDate = new java.util.Date(); creates a new instance
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
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  i want difference between the date entered in a jtextfield and the system date in java
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
Convert String to Date
; In this example we are going to convert String into date. In java date.... It allows the interpretation of date in year, month, day, hour, minute, and second... for December.  3.  A date (day of month) is represented by an integer
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 
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 Date Conversion
Java Date Conversion In java date conversion, two packages are used... of date in year, month, day, hour, minute, and second values. It also allows... for December.  3.  A date (day of month) is represented by an integer from 1
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 
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 date to String, Convert date object into a string with a pattern
Convert date object into a string with a pattern This section illustrates you the conversion of date object into a string pattern. Java has provide many classes for formatting and parsing the date and time. Here we have used
Day Format Example
Day Format Example       This example shows how to format day using Format class. In this program we use a pattern of special characters to day format. Description of the code
Convert Date To Calendar
fields such as YEAR, MONTH, DAY, HOUR, and so on. A Date object represents... Convert Date To Calendar       In this example we are converting  date
ask java - Date Calendar
but in java i found too but i can't to join in another frame. And i want to ask how to subtract a date, ex:i work since 2008/09/01 so i'am work until now 1 month 10 day right, how to get 1 month 10 day?.need help please give me a way and tutorial
date - Java Beginners
date  1.Write a program to check input date is valid or not using java(value must be given by user)  Hi Friend, Try the following code... DateValidation{ public boolean isValidDate(String date){ SimpleDateFormat sdf = new
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
Date picker in Java Swing
Date picker in Java Swing  Hello Sir, Sir ,I am in need of Time Picker just like the Date picker available in java Swing. Kindly... link: Java Date Time Picker Example   Hello Sir, Thank
continue java - Date Calendar
continue java  and how to subtract date(day month year) form jframe...); String df2 = date + "-" + month + "-"+ year; int day = 0; int..._month == 11){ no_of_days = 30; } if(cur_date > date){ day = cur
How to design a day and night process, design a day and night process, day and night process
How to design a day and night process       You will be able to make a day process by this example, It will teach you to convert a day to night by animation. 
java again - Date Calendar
(Calendar.DATE); String df2 = date + "-" + month + "-"+ year; int day = 0; int...; } if(cur_date > date){ day = cur_date - date; }else{ day = cur_date...java again  I can't combine your source code yesterday, can you help
Formatting a Date Using a Custom Format
Formatting a Date Using a Custom Format In this section, you will learn how to format a date using a custom format. Java has provide many classes that allow a programmer to format the date and time. Here we have used SimpleDateFormat
Java Coding - Date Calendar
Java Coding  Write a program that prompts the user to enter the year and first day of the year and displays the calendar for the year on the console. For example,if the user entered the year 2005, and 6 for Saturday, January
Java Date
The Java Date class allows the developers to manipulate date and time from within the Java program. The Java Date class is very useful... the date with the Java Date or calendar class.   The Java Date class
java date selector ..
java date selector ..  hey,,,, i am creating my java project... start day inputs..3 combo(sy,sm,sd) yyyy ,mm,dd and for returning day i need to get 3 combo inputs(ry,rm,rd)... so when i update starting day... others should
Date validation in JSP
language="java" %> <html> <head><title>Date... Date validation in JSP       Example for validating date in a specified format in a JSP page This example illustrates
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.