Results 1 to 4 of 4
  1. #1
    kevinkhan is offline Member
    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0

    Default date difference question

    When i run this code

    System.out.println(pay.getDate());

    i get back a dates in this format

    Thu Jan 12 00:00:00 GMT 2012
    Sat Nov 10 00:00:00 GMT 2012
    Mon Dec 12 00:00:00 GMT 2011

    How do i convert these dates so that i can use the following code

    Java Code:
     Calendar ca1 = Calendar.getInstance();
            Calendar ca2 = Calendar.getInstance();
    
            // Set the date for both of the calendar to get difference
            ca1.set(2008, 07, 27);
            ca2.set(2009, 05, 15);
    
            // Get date in milliseconds
            long milisecond1 = ca1.getTimeInMillis();
            long milisecond2 = ca2.getTimeInMillis();
    
            // Find date difference in milliseconds
            long diffInMSec = milisecond2 - milisecond1;
    
            // Find date difference in days 
            // (24 hours 60 minutes 60 seconds 1000 millisecond)
            long diffOfDays = diffInMSec / (24 * 60 * 60 * 1000);
    
            System.out.println("Date Difference in : " + diffOfDays + " days.");
    Also how can i use the current date for ca2.set(2009, 05, 15);

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: date difference question

    What does getDate() return?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    kevinkhan is offline Member
    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0

    Default Re: date difference question

    returns a date in this format

    Thu Jan 12 00:00:00 GMT 2012
    Sat Nov 10 00:00:00 GMT 2012
    Mon Dec 12 00:00:00 GMT 2011

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: date difference question

    Assuming you mean a Date object, then that has no format.
    If it is a Date then look at the Calendar API for a suitable method.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. combo box date question
    By stuckonjava in forum New To Java
    Replies: 3
    Last Post: 03-25-2012, 01:55 PM
  2. Replies: 5
    Last Post: 02-16-2012, 09:26 AM
  3. Problem with date difference
    By Mick in forum New To Java
    Replies: 4
    Last Post: 10-10-2010, 11:26 AM
  4. Difference between current date and anothe date
    By vijay balusamy in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 04:15 PM
  5. oracle query with date question
    By orchid in forum JDBC
    Replies: 1
    Last Post: 05-09-2007, 12:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •