• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

epoch is wrong

 
Ranch Hand
Posts: 209
13
VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would have expected this code to print:

Thu Jan 01 00:00:00 GMT 1970



But it doesn't. I get:

The epoch: Thu Jan 01 01:00:00 GMT 1970

It's an hour wrong. Anyone know why?


Richard
 
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Probably because your default time zone is an hour ahead of Greenwich mean time. Note that Dates represent an absolute point in time, independent from your location. But when you print a Date, it has to convert it into some sort of textual representation, which of course *does* depend on your location.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And if you use a SimpleDateFormat that includes a TZ, I bet you'll see that 01:00 in that TZ is 00:00 in GMT.

Apparently I misunderstood the question. Fortunately, others have examined it more closely.
 
Stephan van Hulst
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I notice now that your date string says GMT. The discrepancy might arise from daylight savings which is not displayed in the toString() method. Regardless, like Jeff suggested you should probably always use a DateFormat to print points in time.
 
Master Rancher
Posts: 4796
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Daylight savings certainly can be used inside the toString() method of Date - but any time zone labeled as GMT has absolutely no business using daylight savings time. Ever. So something is pretty screwed up there in how the JDK is printing the localized time.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Probably because your default time zone is an hour ahead of Greenwich mean time. . . .

I remember the epoch. I was around to watch. It was in fact at 1.00am, not midnight, because we had summer time (daylight saving time) all winter that year. It was pretty unpleasant, so in1971 we went back to GMT in winter.
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It was not called GMT, but BST = British Standard Time, back then.
 
Stephan van Hulst
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Simmons wrote:Daylight savings certainly can be used inside the toString() method of Date - but any time zone labeled as GMT has absolutely no business using daylight savings time. Ever. So something is pretty screwed up there in how the JDK is printing the localized time.


Good point. I'm at a loss why it prints that the way it prints it.

For me it correctly prints "Thu Jan 01 01:00:00 CET 1970".
 
Mike Simmons
Master Rancher
Posts: 4796
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:It was not called GMT, but BST = British Standard Time, back then.


Well, that would certainly confuse things, given what BST means now.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed strange that the hour is off by one while the time zone is GMT.

I tried the following on my system (JDK 1.7.0 update 3, 64-bit, on Ubuntu 11.10):

Output exactly as I'd expect (my local time zone is CET):


Thu Jan 01 01:00:00 CET 1970
1970-01-01 00:00:00 GMT (+0000)
1970-01-01 00:00:00 UTC (+0000)


 
Richard Hayward
Ranch Hand
Posts: 209
13
VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Stephan van Hulst wrote:Probably because your default time zone is an hour ahead of Greenwich mean time. . . .

I remember the epoch. I was around to watch. It was in fact at 1.00am, not midnight, because we had summer time (daylight saving time) all winter that year. It was pretty unpleasant, so in1971 we went back to GMT in winter.



Hi Campbell,

Apologies for being thick, but is this an explanation for the Date(0) being an hour wrong, or is it just banter?

Richard
 
Richard Hayward
Ranch Hand
Posts: 209
13
VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:Indeed strange that the hour is off by one while the time zone is GMT.

I tried the following on my system (JDK 1.7.0 update 3, 64-bit, on Ubuntu 11.10):

Output exactly as I'd expect (my local time zone is CET):


Thu Jan 01 01:00:00 CET 1970
1970-01-01 00:00:00 GMT (+0000)
1970-01-01 00:00:00 UTC (+0000)




When I first posted, I was testing on XP with java version 1.7.0_03.
I've now tested, like you did on Ubuntu 11.10 with java 1.7.0_3, although 32 bit,
but I get the same discrepancy as before.

Interestingly, if I make a DateFormat and ask it's TimeZone, I get GMT. But Date(0) is an hour wrong.
If I then explicitly set the TimeZone to GMT, as you did, it gets Date(0) correct. Odd...




richard@Shakespeare:~/projects/java/classes$ java EpochTest
System's Timezone: Greenwich Mean Time
TimeZone of newly created DateFormat = Greenwich Mean Time
Thursday, 1 January 1970 01:00:00 o'clock GMT
Thursday, 1 January 1970 00:00:00 o'clock GMT



Regards
Richard
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's really strange, as if there are two variants of the time zone "Greenwich Mean Time"? This is either a bug in Java, or there is some special reason for this that we don't understand.

I wrote a small program using Joda Time, an alternate date and time library for Java (with a much better designed API than Java's standard Calendar and Date classes).

It doesn't show an offset of an hour on my system:


1970-01-01 00:00:00 +00:00 (+0000)


 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Guy Hayward wrote: . . .

Apologies for being thick, but is this an explanation for the Date(0) being an hour wrong, or is it just banter?

. . .

Half and half. If you were in a GMT area (Britain) the epoch fell at 1.00am. In other places, eg parts of Africa, which are in the GMT zone, it would have been at midnight. The fact that you are showing GMT might suggest an error. I managed to get 1.00am from System.out.println(new Date(0L)); so the behaviour is at least reproducible; that would appear to be the same as what Jesper did. Whether our having summer time all winter in 1970 is the explanation, I am not sure. It does say midnight here.
 
Richard Hayward
Ranch Hand
Posts: 209
13
VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all for your help on this thread.

I think I'll have to leave it as an unexplained mystery for the moment.

Regards
Richard
 
straws are for suckers. tiny ads are for attractive people.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic