Question: Java Date Class

Ads

 
 
 

Share on Google+Share on Google+

danish ali
Java Date Class
0 Answer(s)      5 years and 6 months 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");
    }
}

}

Ads
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
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 class and it is used... in your program you will have to use the Java Class to manipulate the date
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
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
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 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
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
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 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 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
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 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
Tutorials   
Java Spring Hibernate Struts Training Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java Java Example Codes and Tutorials in 2017 How do I read a large file quickly in Java? Is learning Java worthwhile? How to create first Java Program? Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include?

Ads

 
Advertisement null

Ads