Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timestamp.valueOf() returns different value according to JVM version

Tags:

Timestamp sTs = Timestamp.valueOf("1900-12-31 23:59:59.999"); // Make Timestamp
System.out.println("sTs====>" + sTs.getTime());

sTs====> -2177485200001  // in jdk 1.4


Timestamp sTs = Timestamp.valueOf("1900-12-31 23:59:59.999"); // Make Timestamp
System.out.println("sTs====>" + sTs.getTime());

sTs====> -2177483400001  // in jdk 1.5

Why are the two values different?

like image 593
user3659756 Avatar asked May 21 '14 08:05

user3659756


2 Answers

According to a now deleted post on the Sun website

Daylight Saving Time (DST) is a system of handling the changing amounts of daylight throughout the year. The goal of DST is to maximize the daylight hours available during typical waking hours. By adjusting clocks ahead a standard amount, usually an hour, people can have more daylight available during their typical work day. For example, suppose you wake daily at 7:00 AM. In the spring, the sun rises earlier each day. Instead of waking up at 6:00 AM to take advantage of the daylight, DST observers move their clocks ahead an hour. The effect is that they can continue to wake at 7:00 AM according to the clock and enjoy more daylight. In the fall, people set their clocks back an hour as sunrise happens later each day.

The United States has planned a change to its DST observance beginning in 2007. The Energy Policy Act of 2005 mandates that DST will start on the second Sunday in March and end on the first Sunday in November. In 2007, the start and stop dates will be March 11 and November 4, respectively. These dates are different from previous DST start and stop dates. In 2006, the dates were the first Sunday in April (April 2, 2006) and the last Sunday in October (October 29, 2006).

The Java Runtime Environment (JRE) stores rules about DST observance all around the globe. Older JREs will have outdated rules that will be superseded by the Energy Policy Act of 2005. As a result, applications running on an older JRE may report incorrect time from March 11, 2007 through April 2, 2007 and from October 29, 2007 through November 4, 200

The change was updated in Java 1.4.2_13. So if your version is older then that you'll see different behaviour.

like image 170
Joel Witteveen Avatar answered Sep 18 '22 03:09

Joel Witteveen


I think this is because 1.4 probably does not support timezone historical changes (http://www.timezoneconverter.com/tzchist.html). The problem is that Timestamp parses time in local timezone and timezone in your locale was different in 1900 which 1.4 did not take into account but 1.5 did

like image 40
Evgeniy Dorofeev Avatar answered Sep 19 '22 03:09

Evgeniy Dorofeev