Java Date Class

Ads
 

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

Ads









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
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
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
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 util date
Java util date         The class Date in "java.util" package represents... to string and string to date. Read  more at: http:/www.roseindia.net/java/java
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
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
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 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 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
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
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
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
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
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 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 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
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 Class Size
Java Class Size  How to determine size of java class
How to convert date to string in Java?
How to convert date to string in Java?  Hello developers, I have... date to string in Java? Thanks   Hi, To convert java.util.Date object... */ /* * In this example we convert current date to String */ public class
class method in java
class method in java  How to write a class method in Java?   You must read Java - Class, Object and Methods in Java
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
Java inner class and static nested class
Java inner class and static nested class  Java inner class and static nested class
Example of HashMap class in java
Example of HashMap class in java. The HashMap is a class in java collection framwork. It stores values in the form of key/value pair. It is not synchronized
Java class file
Java class file  How do i open a java class file using eclipse
Java class in JSP
Java class in JSP          To use a Java class method in jsp first we need to import a package inside which there is java class. We will import the package
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
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
How to create a class in java
How to create a class in java  I am a beginner in programming and tried to learn how to do programming in Java. Friends please explain how can I create a class in Java
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
java date selector ..
java date selector ..  hey,,,, i am creating my java project... be updated public class Traval_guider extends javax.swing.JFrame... java.awt.event.*; public class GetDate{ static String months[]={"Month

Ads