Share on Google+Share on Google+

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

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

Ads

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
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: <?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
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
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
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
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
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
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
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 
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
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
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
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
Tutorials   
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized

Ads

 
Advertisement null

Ads