为什么当年份小于1884时,它会删除几毫秒? [英] Why when year is less than 1884, it remove few milliseconds?

查看:96
本文介绍了为什么当年份小于1884时,它会删除几毫秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DateTime start = new DateTime().withYear(1884);
System.out.println(start);
System.out.println(start.minusYears(1));

输出

1884-01-11T08:26:10.234-08:00
1883-01-11T08:26:10.234-07:52:58

我说的不对.它没有删除1.02秒

Edit 1: I was not correct. It did not removed 1.02 sec

DateTime start = new DateTime().withYear(1884);
DateTime other = start.minusYears(1);
long diffMs = start.getMillis() - other.getMillis(); //31536422000

有趣的是,我对toString();-(-08:00-07:52:58)

Interesting, I was confused by the output for toString(); - (-08:00, -07:52:58)

使用Java日历,我看不到任何差异:

With Java Calendar, I don't see any differences:

Calendar cal = Calendar.getInstance();
cal.set(start.getYear(), 
        start.getMonthOfYear(), 
        start.getDayOfMonth(), 
        start.getHourOfDay(), 
        start.getMinuteOfHour(), 
        start.getSecondOfDay());
System.out.println(cal.getTime());

cal = Calendar.getInstance();
cal.set(start.getYear()- 1, 
        start.getMonthOfYear(), 
        start.getDayOfMonth(), 
        start.getHourOfDay(), 
        start.getMinuteOfHour(), 
        start.getSecondOfDay());
System.out.println(cal.getTime());

输出:

Mon Feb 11 18:46:42 PST 1884
Sun Feb 11 18:46:42 PST 1883

推荐答案

来自此时区历史记录页面;

1883年11月18日引入了美国大陆的四个标准时区.英国已经对英格兰,苏格兰和威尔士采用了自己的标准时区,并于1884年为国际时区达成了国际共识./p>

Four standard time zones for the continental United States were introduced on November 18, 1883. Britain, which already adopted its own standard time system for England, Scotland, and Wales, helped gather international consensus for global time zones in 1884.

换句话说,美国时区在这两个时间戳之间改变.

In other words, the US time zones changed between those two timestamps.

如果将您的时区设置为PST(时区),则不会看到此效果,而如果将其设置为某个位置(例如America/Los_Angeles),则可以看到.这是因为 PST的时区偏移未更改,而是创建了PST,洛杉矶从LMT更改为PST.也就是说,洛杉矶时间已更改,而PST却没有.

If you have your time zone set to PST (the time zone), you will not see this effect, while if you have it set to a location (for example America/Los_Angeles), you will. This due to that the time zone offset of PST didn't change, instead PST was created and Los Angeles changed from LMT to PST) That is, Los Angeles time changed, while PST didn't.

作为一个演示,您可以在linux上尝试;

As a demo, you can try this on linux;

# PST test
$ TZ=PST8PDT date -d '1883-01-01 12:00:00 UTC'
Mon Jan  1 04:00:00 PST 1883

# America/Los_Angeles test
$ TZ=America/Los_Angeles date -d '1883-01-01 12:00:00 UTC'
Mon Jan  1 04:07:02 LMT 1883

这篇关于为什么当年份小于1884时,它会删除几毫秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆