SnippetCollection
Forums  
Links
 
Support
 


snippetCollection.com Forum Index FAQ Memberlist Search Usergroups Profile Log in to check your private messages Log in Register
Welcome to SnippetCollection.com, a friendly and fast growing community of programmers, coders, web application developers and more. You are currently viewing our forums as a guest!

This message will go away once you are registered. Also, by registering you will have access to all post topics, communicate privately with other members (PM), respond to polls and access other special features. Registration is fast, simple and absoultely free so please Click Here to join our community

Enjoy our great collection of snippets and tutorials!

Log in
Username:
Password:

 

Our Sponsors
           
Want to list your business here. Contact us.
 Difference between current date and future date View next topic
View previous topic
Post new topic Reply to topic
Author Message
corolla



Joined: 05 Sep 2005
Posts: 39
Location: Valletta

PostPosted: Fri Mar 17, 2006 6:39 pm Reply with quoteBack to top

Code:


import java.io.*;
import java.util.*;
import java.text.*;
import Standinpout.*;

public class DateProg {

  /*  Demonstrates Java support for dates
   */


public static void main (String [] args) throws IOException {

    BufferedReader inp = StdIO.open(System.in);

    // Introductory messages
         StdIO.prompt("Enter some future date as dd/mm/yy: ");
      String s = StdIO.readString(inp);

    DateFormat DF = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ITALY);
       Date today = new Date ();
      Date d = new Date ();
      try {
        d = DF.parse(s);   // entered date
      } catch (ParseException e) {
          System.out.println("Error in date " + s);  // date entered is                                                 
                                                                               //not good   
       }

  System.out.println("Today's date is: " + today);
  System.out.println("Date entered was: " + d);
  long dif = (d.getTime()-today.getTime())/(1000*60*60*24)+1;
 System.out.println("Number of days between the dates is: " + dif);
 // use Calendar and GregorianCalendar class
}
}

Display posts from previous:      
Post new topic Reply to topic


 Jump to:   



View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group :: FI Theme
All times are GMT