java - Timestamp.valueOf() 根据 JVM 版本返回不同的值

标签 java datetime

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

为什么这两个值不同?

最佳答案

根据 Sun 网站上现已删除的帖子

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

此更改已在 Java 1.4.2_13 中更新。因此,如果您的版本较旧,那么您会看到不同的行为。

关于java - Timestamp.valueOf() 根据 JVM 版本返回不同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23778107/

相关文章:

python - 更改 zip 文件元素的上次修改时间

java - 当前日期和时间 ("Wall"任何时区的日期和时间

php - 如何在 php mysql 中将 varchar 转换为日期?

php - 获取从现在到 x 天后的所有日期

java - str[newLength] = '\0' 是什么意思?

c# - 转换为日期时间格式

java - 找出JDT中调用的方法的类型

java - 耳朵部署期间的飞路迁移

java - 使用方法在数组中搜索唯一名称

java - Future 中的代码是否有机会在之后的主线程中的代码之前运行?