Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java daylight saving time does not work for distant past (UPDATE: It does)?

Tags:

java

date

dst

The following piece of code:

TimeZone.getTimeZone("Europe/Athens").inDaylightTime(new Date(200, 8, 14));

returns true, much like it does for the year 2011. However, Daylight Saving Time (DST) was only proposed 100 years or so ago, and applied even more recently. Is the time in the year 200 considered DST, or is this a Java quirk?

like image 934
Markos Fragkakis Avatar asked May 06 '26 11:05

Markos Fragkakis


1 Answers

You are mistaken. It works as expected when you use the date new Date(-1700, 8, 14) (which is year 200). The constructor you are using is adding 1900 to your year. You are actually using year 2100.

Check the Date constructor api.

like image 83
dacwe Avatar answered May 08 '26 00:05

dacwe