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



Home Answers Viewqa Java-Beginners Java Date Class

Have Programming Question? Ask it here!
 
 
 


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

}


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 class
Java class  What is the purpose of the Runtime class
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 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 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 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
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 date - Java Beginners
java date   Hi, Please observe the below code: import...*; class LoginDemo{ JButton SUBMIT; JFrame f; JLabel label1,label2; final... is "login" the name,date,time is automaticaaly inserted into the database . My
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
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
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
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
Day for the given Date in Java
Day for the given Date in Java  How can i get the day for the user... java.util.*; import java.text.*; class CheckDay{ public static void main...("Enter date(1-31):"); int dd=input.nextInt(); System.out.println("Enter
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
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
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
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
Date Class time units values example
.style1 { font-size: medium; } Date class time units values...; height="280" title="Date Class Panel with Time units..., we have created a Date class object after that we have used some properties
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
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
java - Date Calendar
java   Using java how can i change the date format of the system from mm/dd/yy to dd/mm/yy. The code which i wrote is changing the format only on the console and not on the system's control panel.Can you suggest me anything
continue java - Date Calendar
continue java  and how to subtract date(day month year) form jframe... javax.swing.JPanel; import javax.swing.JTextField; public class SwingDate extends...(); } } }); } public void getDiffer(String dt1, String dt2) throws ParseException{ Date
Java Increment Date. - Java Beginners
Java Increment Date.  Create a program called Date.java to perform... have so far: public class Date { private int day; // 1-31... the following code: public class Date { private final int month; private
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
Java Date Utility - Java Beginners
Java Date Utility  How to determine the maximum number of weeks in a year (52 or 53) as per the ISO Calendar? Is there any standard method in java... java.util.*; public class GetWeeks{ public static int
Advertisements
 

 

 

DMCA.com