Java Date Class

Java Date Class

Hi Friend, I need to have a code to get the days between specific dates. Such if I enter 19 September 2011 to 21 September 2011, the days would be saturday, sunday and monday, the code I gave simply get one day, but i need to able to enter few dates and the output should be the the days, please let me know, thanks

This is my code:

import java.util.Scanner; public class DateClassExample {

public static void main(String[] args)
{
    Scanner userIn = new Scanner(System.in);
    int dates, day, dayOfMonth, month, century, year;

    System.out.print("Enter year(e.g:2001): ");
    year = userIn.nextInt()%100;

    System.out.print("Enter month(1-12): ");
    month = userIn.nextInt();

    System.out.print("Enter days(1-31): ");
    dayOfMonth = userIn.nextInt();

    System.out.print("Days of the week are: ");

    century = year/100;

    if (month == 1){
        month = 13;
        year = year-1;
    }

    if (month == 2){
        month = 14;
        year = year-1;
    }

    day = ((dayOfMonth +((26*(month+1))/10) + year + (year/4) + (century/4) + (5*century))%7);

    if (day == 0){
        System.out.println("saturday");
    }
    if (day == 1){
        System.out.println("sunday");
    }
    if (day == 2){
        System.out.println("monday");
    }
    if (day == 3){
        System.out.println("tuesday");
    }
    if (day == 4){
        System.out.println("wednesday");
    }
    if (day == 5){
        System.out.println("thursday");
    }
    if (day == 6){
        System.out.println("friday");
    }
}

}

View Answers









Related Tutorials/Questions & Answers:
Java Date Class
Java Date Class  Hi Friend, I need to have a code to get the days between specific dates. Such if I enter 19 September 2011 to 21 September 2011... class DateClassExample { public static void main(String[] args) { Scanner
clarify date class - Java Beginners
clarify date class  Dear, clarify this question... "Develop Date class in Java similar to the one available in java.util package. Use JavaDoc comments." Give me the source code and explain how to create classes similar
Advertisements
user defined date class
user defined date class  Develop a user defined date class with public.Fill the members using existing class method.implement the methods for finding current date(),days between method,advanced days and after days
user defined date class
user defined date class  Develop a user defined date class with public.Fill the members using existing class method.implement the methods for finding current date(),days between method,advanced days and after days
Implement Date Class
Implement Date Class The class Date represents a specific instant in time..., and second values. It also allowed the formatting and parsing of date strings. Here we are going to implement Date Class. Here is the code: public class Date
Date Class In Action Script
.style1 { font-size: medium; } Date Class in Action Script 3:- If user... class that provide date and time related information. User access the current... class in the application. The Date class is the top-label class that provide
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 util date
Java util date         The class Date in "java.util" package represents date and time. It's no arguments constructor creates date object specifying current
Date Class with Single String parameter constructor example
.style1 { font-size: medium; } Date class with single string parameters to the Date() constructor example:- The Date class have a single string parameterized constructor. If user pass a string parameter in the date class
Flex DateChooser with Date Class
DateChooser with Date Class:- In this tutorial you can see how to use DateChooser with the help of Date Class in flex and how to use it. DateChooser control..., or access the Date in the selectedDate property. The Date class has many methods
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
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 class
Java class  What is the purpose of the Runtime class
Java programme - Date Calendar
Java programme  Can you provide me the coding for Date class provided by java util package
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
Example of Date class
Example of Date class       We can use Date class to use current date. In this program we are creating a Date object and by using it we are going to display the current date
Date Class time units values example
.style1 { font-size: medium; } Date class time units values...; In this example, we have created a Date class object after that we have used some properties or method of  Date class to find the time
Date Class with multiple numeric parameter constructor
.style1 { font-size: medium; } Date class with multiple numeric... Date class object and pass multiple numeric parameters as  the year, month... a corresponding Date object. The date class object take time information
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
java class
java class  write a java program to display a msg "window closing" when the user attempts to close the window.(a) create a window class (b) create frame within the window class (c) extends window adapter class to display the msg
Java Date Conversion
Java Date Conversion In java date conversion, two packages are used... the formatting and parsing of date strings. The Calendar class of JDK 1.1 is ...; within the class returns a date/time.formatter with a default format pattern
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...*; public class StringToDate{ public static void main(String[] args){ try { String
java class
java class  please send me the answer of the question which i have send according of java class assoon as possible . Write a java program to display.... a. Create a window class. b. Create frame within the window class. c. Extend
java format date
java format date  Hi, How can I format the date in the following pattern? yyyy-MM-dd   import java.util.*; import java.text.*; class...) { Date date=new Date(); SimpleDateFormat sdf=new SimpleDateFormat("yyyy
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: import java.util.*; import java.text.SimpleDateFormat; class
Java String To Date
. Java provides two types of Date class from different packages...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
Date Java - Java Beginners
: public class Date { private int month; // 1-12 private int day; // 1-31...; } } // end class Date public class DateTest { public static void...' therefore you have got the error.Save your java class as DateTest.java and remove
java yesterday - Date Calendar
java yesterday  And how to make date format DD/MM/YYYY,thank's ...; import java.text.SimpleDateFormat; public class SimpleFormatDate { public static void main(String args[]){ Date todaysDate = new java.util.Date
java Date - Java Beginners
java Date  Dear sir I have an assignment, It is .. "Develop Date class in java similar to the one available in java.util package.Use JavaDoc..., Try the following code: public class Date { private final int month
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
What is Calendar class in Java?
This class is used for various date processing activities in Java. You can...What is Calendar class in Java?  Hi, What is Calendar class in Java? I want to learn about this class to make use of it in Java programs. Thanks
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
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...; import java.text.SimpleDateFormat; import java.util.*; public class DayDiff
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
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 how about 1 year and 1 month? And Can help me to using Date Calender what
Java inner class and static nested class
Java inner class and static nested class  Java inner class and static nested class
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 
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 
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... class ShowTime extends JFrame{ ShowTime(){ JTextField text=new JTextField
date format - Java Beginners
date format  How to convert yyyy-mm-dd to dd-mmm-yyyy  Hi...; import java.text.*; public class SimpleFormatDate1 { public static void main(String args[]) throws Exception{ Date todaysDate = new java.util.Date
Day for the given Date in Java
Day for the given Date in Java  How can i get the day for the user..._TO_REPLACE_1 import java.util.*; import java.text.*; class CheckDay{ public static...); System.out.println("Enter date(1-31):"); int dd=input.nextInt
date format - Java Beginners
date format  how to 45day in dd-mmm-yyyy date format.  Hi...; public class AddDaysToDate { public static Calendar parseTimestamp(String...-yyyy", Locale.US); Date d = sdf.parse(timestamp); Calendar cal
date picker - Java Beginners
date picker  sir i need code for date picker in java swing because for Embedding in my project plz sir
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
How to get the current date in Java?
(); and with the help of Formatter class you can format the date. Check the tutorial: 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
Date - Java Beginners
Date  how to add 45day in dd-mmm-yyyy date format but not current...; import java.text.SimpleDateFormat; public class AddDaysToDate { public... { SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", Locale.US); Date d
Java Class Size
Java Class Size  How to determine size of java class
java again - Date Calendar
java again  I can't combine your source code yesterday, can you help... : Date now : jtextfield1 //jTexfield1=date now //we enter ,then result in jTextfield2 Date work : jtextfield2 This my Source
Java inner class
Java inner class  What are inner class and anonymous class
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

Ads