Day for the given Date in Java

Day for the given Date in Java

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 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... SimpleDateFormat("EEEE"); String day=f.format(date); System.out.println(day...); System.out.println("Enter date(1-31):"); int dd=input.nextInt
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
How to get day from date in Java using Calendar?
How to get day from date in Java using Calendar?  Hi, I have a calendar object in my Java program. How I can get the day of date from this? How to get day from date in Java using Calendar? Thanks   Hi, If you don't
python add one day to date
python add one day to date  Hi, I have date object and I want to add one day to the date. How to add one day to the date in Python code? Thanks...%d') print(date) next_day_date = date + timedelta(days=1) print(next_day_date
python add one day to date
python add one day to date  Hi, I have date object and I want to add one day to the date. How to add one day to the date in Python code? Thanks...%d') print(date) next_day_date = date + timedelta(days=1) print(next_day_date
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
python add 1 day to date
python add 1 day to date  Hi, In one of my project I am getting date from the some datasource and now I have to add one day to the date. How I can add 1 day to date in my Python program. Thanks   Hi, Here is example
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:ADS_TO_REPLACE_1..."); String day=f.format(date); if(day.equals("Sunday")){ System.out.println
How to get day from date in SQL?
How to get day from date in SQL?  Hi, How to get day from date...;Hi, You can use the following queries to get the data: select date_format(now(),'%e')as day; select day(now()) as day; Thanks
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:ADS_TO_REPLACE_1...;Today: ".$todayDate."<br>"; //Add one day to today $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:ADS_TO_REPLACE_1 DECLARE @dtDate DATETIME SET @dtDate = '8/18/2007' SELECT
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
How to get day of week in Java?
How to get day of week in Java?  Hi, How to get day of week in Java? Thanks   Hi, Calendar class is very useful in Java. You can use this class for getting the day of the week. Here is sample code: int weekday
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..._IN_DAY);   System.out.println("Previous date: " 
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 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
Mysql Date Minus Days
; Query for viewing date after subtracting 2 day from current date:- The given below Query return you the date after subtracting 2 day from current date. ...; The Tutorial cover on Mysql Date Minus Days return you the day after
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
How to learn Java in just one day
day? Thanks   How to learn Java in just one day? If you have spent... the basics of Java which is necessary to get started with Java in just one day. After learning for one day will be good at Java basics. Start a new project Start
Java Date
Java Date  Hi, What is the API for Date management in Java? How use the Java Date API for manipulating date object in Java? Provide some... of API for working with date and time objects in Java. You can also use third
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
Get first day of week
Get first day of week       In this section, we will learn how to get the first day of  week in Java. As we know that GregorianCalendar provides the current date, month
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
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 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
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 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 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
Get Last Day of The Month
and a set of integer fields such as YEAR, MONTH, DAY, HOUR.. A Date object ... the maximum value for this field, given the current date and store its value int variable... Get Last Day of The Month     
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
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 class and it is used... in your program you will have to use the Java Class to manipulate the date
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
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
Mysql Date To Java Date
Mysql Date To Java Date       Mysql Date To Java Date retrieve the records from Mysql and display the date in java. Understand with ExampleADS_TO_REPLACE_1 The Tutorial illustrate
How do I learn Java programming in one day from zero?
How do I learn Java programming in one day from zero?  Hi, I am.... Is there any way of really learning Java in one day? How do I learn Java programming... programming language in one day from zero? Thanks   Hi, Java is so
How do I learn Java programming in one day from zero?
How do I learn Java programming in one day from zero?  Hi, I am.... Is there any way of really learning Java in one day? How do I learn Java programming... programming language in one day from zero? Thanks   Hi, Java is so
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
:\rajesh\kodejava>java DayYearToDayMonth The date of Calendar is: Sat Jun... Find Day of Month       This example explores how to find the day of a month and the day
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
how to add date and change date in java - netbeans
how to add date and change date in java - netbeans  I need to code use to increase date How to get date after 30 days using netbeans
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 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
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
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
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
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

Ads