Results 1 to 3 of 3
  1. #1
    garinapavan is offline Member
    Join Date
    Aug 2007
    Posts
    5
    Rep Power
    0

    Default DataObject with the time given by me

    c.set(Calendar.HOUR,21);
    c.set(Calendar.MINUTE,46);
    c.set(Calendar.SECOND,20);
    Date timeToRun=c.getTime();
    System.out.println("date="+timeToRun);

    o/p:date=Tue Aug 07 09:46:20 PDT 2007

    Why is it taking the next day(In my example my todays date is aug06) date and the time specified by me.It need to be the current date and the time specified by me......... right? I see the time is set properly but when coming to date it is giving me the next day date.

    Then how to get the date object witn the current date and with the time specified by me ?

    Ragards
    navap

  2. #2
    shanePreater is offline Member
    Join Date
    Jul 2007
    Location
    England, Bath
    Posts
    47
    Rep Power
    0

    Default

    You need to use HOUR_OF_DAY instead of HOUR as you are trying to use the 24 hour clock.
    HOUR is specified in the javadoc as :

    Field number for get and set indicating the hour of the morning or afternoon. HOUR is used for the 12-hour clock. E.g., at 10:04:15.250 PM the HOUR is 10.

    so it is rolling the time forwards by 12 hours from what you requested hence 09 the next day instead of 21 the right day.

    Hope this makes sense,
    Shane.

  3. #3
    garinapavan is offline Member
    Join Date
    Aug 2007
    Posts
    5
    Rep Power
    0

Similar Threads

  1. Hello, first time here.
    By ludragon in forum Introductions
    Replies: 2
    Last Post: 01-03-2008, 05:03 AM
  2. help with dates and time
    By osval in forum New To Java
    Replies: 3
    Last Post: 12-12-2007, 12:41 PM
  3. Method execution time
    By javaplus in forum Advanced Java
    Replies: 3
    Last Post: 11-26-2007, 09:51 AM
  4. Time method
    By carderne in forum New To Java
    Replies: 5
    Last Post: 11-05-2007, 09:34 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
  •