Day for the given Date in Java

Ads
 

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);  
                }  


        }
 }

}

Ads









Related Tutorials/Questions & Answers:
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
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
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 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
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
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
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
How to compare date in Java?
How to compare date in Java?  Hi, How to compare date in Java? Thanks   Hi, Check this example Date Comparison. Thanks
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
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
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 Example The Tutorial illustrate an example from
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
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
Java String To Date
Java String To Date In this section you will read about how to convert... be convert into java.util.Date. Java string to date convert explains the conversion of Java string written into the specified format to a Java date object
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
Parsing date in Java
Parsing date in Java  How can i parse the date in Java in a simple format..?   SimpleDateFormat parserSDF=new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy
java format date
java format date  Hi, How can I format the date in the following...) { Date date=new Date(); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); String formattedDate=sdf.format(date
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
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
date and time in awt(java)
date and time in awt(java)  sir, do you have an example of date in awt java which can be view over a textfield.   Display time in JTextField import java.util.*; import javax.swing.*; import java.awt.event.*; public
Getting Computer Date in java
Getting Computer Date in java  Hi , I want to get the PC Date... but this.. String strDate = new Date(); I get this server error, "The type Date is ambiguous". I've also tried Date date = new Date(); ... but it get's the same error
How to get the current date in Java?
How to get the current date in Java?  Hi, I am new to Java... in Java? Thanks   Hi, Check the tutorial: Java program to get current date. Thanks   Hi, To get the current date and time in Java you can use
date picker componnt - Java Beginners
date picker componnt  sir i need code for date picker in java swing for my project sir please send me sir
Java date add months
Java date add months In this tutorial, you will learn how to add months... of that day. For this, we have created a calendar instance and get a date... the date of that day. Example: import java.util.*; public class AddMonthsToDate
Java date add year
Java date add year In this tutorial, you will learn how to add years to date. Here, we are going to add few years to current date and return the date of that day. For this, we have created a calendar instance and get a date
Java converts any given year to Roman Numeral
Java converts any given year to Roman Numeral  Write a program that converts any given year to Roman Numeral
How to calculate Date Difference in Java?
How to calculate Date Difference in Java?  Hi, I have two dates variable. How to calculate Date Difference in Java? Thanks   Hi, You can use the Calendar class for calculating the date difference in Java. Get data
Java current date - How to get current date in Java
In this section, you will learn about displaying current date and time in Java
How to convert date to string in Java?
How to convert date to string in Java?  Hello developers, I have java.util.Date object and it has to be converted to date format. How to convert date to string in Java? Thanks   Hi, To convert java.util.Date object

Ads