Results 1 to 4 of 4
  1. #1
    wangalex is offline Member
    Join Date
    Nov 2010
    Rep Power

    Default GregorianCalendar bug?

    I've been using GregorianCalendar to compute time difference between two dates. The package works well most of the time except at one mysterious time interval : March 8 around 2 and 3 am. The computation of elapsed time is always off in this interval.

    For example,

    Time 1 : 2009-03-08 03:07:44
    Time 2 : 2009-03-08 02:27:30

    Elapsed time for Time 1 : 343474.12888888887
    Elapsed time for Time 2 : 343474.4583333333

    Time 2 is earlier than Time 1, yet its elapsed time is longer. The code I use to generate the time is simply

    double time = new GregorianCalendar(year, month, day, hour, minute, second).getTime().getTime();

    I have a lot more examples in this interval. Does anybody know what's going on? Am I the only one seeing this? What am I missing? Thanks!!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    For your best chances of getting help, you may wish to create and post a small but complete compilable, runnable program that demonstrates your problem, in sum, an SSCCE.

    Also for what it's worth, any time I've been absolutely, completely, and 100% sure that there's a bug in Java, I've been wrong, and the error has been mine. I guess the folks who created Java are smarter and less prone to creating errors than I am. Perhaps your luck will be better. :)

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power


    You might want to include locale/timezone stuff if that makes the SSCCE repeatable. I note that 2:30 did not exist on that date in the CDT timezone.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

Similar Threads

  1. GregorianCalendar mishap
    By kasur in forum New To Java
    Replies: 9
    Last Post: 07-30-2010, 11:15 AM
  2. GregorianCalendar help
    By Sturm in forum New To Java
    Replies: 0
    Last Post: 02-03-2010, 10:43 PM
  3. Problem with "GregorianCalendar"
    By tola.ch2004 in forum New To Java
    Replies: 2
    Last Post: 07-12-2007, 09:12 PM

Posting Permissions

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