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



Home Answers Viewqa Java-Beginners Java Date Class
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


danish ali
Java Date Class
0 Answer(s)      3 years and a month ago
Posted in : Java Beginners


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

}


Advertisement
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
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
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 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
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
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
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 programme - Date Calendar
Java programme  Can you provide me the coding for Date class provided by java util package
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
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 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
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 - 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
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 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 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 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 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 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 class
Java class  What is the purpose of the Runtime class
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
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
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 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
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 
 

 

 

DMCA.com