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



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

Have Programming Question? Ask it here!
 
 
 


Aghil krishna
Day for the given Date in Java
4 Answer(s)      3 years and 10 months 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
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
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
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
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     
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
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
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 
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 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
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
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
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
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
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
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 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 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 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 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
Learn Java in a day
Learn Java in a day       Java is the most exciting object oriented programming language in computer programming landscape. Java provides
java - Date Calendar
Java convert string to date  I need an example in Java to convert the string to date.  Convert string to date formatimport... str_date="04-04-2008"; DateFormat formatter ; Date date
date picker - Java Beginners
date picker  sir i need code for date picker in java swing because for Embedding in my project plz sir
Java Date - Java Beginners
Java Date  I have to find the previous date's beginning time and end time in the long milliseconds format. for example today date is '23rd April... main(String[] args) { Date now = new Date(); DateFormat df   Hi friend
Java programme - Date Calendar
Java programme  Can you provide me the coding for Date class provided by java util package
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
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
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
 

 

 

DMCA.com