Older dates are parsed as summer time, even if that is not true in Java

77 views Asked by At

I have a problem displaying a number of dates that are stored as longs. I create the date objects with the constructor that takes the long argument, and then print the dates to a PDF file.

However, I have a problem with older dates, when running the program on Linux, compared to Windows.

Take this date: 25. april 1976 00:00:00 (long value: 199231200000L) for example. If I use a dateformater to display the date, it will display differently on Linux and Windows:

On Windows: 25. april 1976 00:00:00 CEST

On Linux: 24. april 1976 23:00:00 CET

The text rep. can be shown simply by running the following line:

DateFormat.getDateTimeInstance( DateFormat.FULL, DateFormat.FULL ).format( new Date( 199231200000L) )

I used Joda Time to get the datevalue for this test:

new org.joda.time.DateTime().withDate( 1976, 4, 25 ).withTime( 0, 0, 0, 0 ).toDate().getTime()

Why does Windows show the output as CEST, and Linux as CET?

1

There are 1 answers

1
Meno Hochschild On BEST ANSWER

France has introduced summer time in 1976, but Denmark started DST in 1980. This explains the differences you observed so all is right except the fact that your system timezones are different. You should better use the same explicit timezone on both machines and not rely on the default timezone.

And by the way, if I look at the timestamps you use then I see no millisecond or just minute portion which makes me thinking if the intention was just to store a pure calendar date. If so then using timezones is in general dangerous as your problem clearly illustrates. Now Java-8 has the type LocalDate for this purpose - fortunately.