Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why when year is less than 1884, it remove few milliseconds?

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

Output

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

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

Edit 2:

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

Edit 3:

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());

Output:

Mon Feb 11 18:46:42 PST 1884
Sun Feb 11 18:46:42 PST 1883
like image 244
JohnJohnGa Avatar asked Jan 11 '13 16:01

JohnJohnGa


2 Answers

From this time zone history page;

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.

EDIT: 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.

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
like image 92
Joachim Isaksson Avatar answered Nov 04 '22 05:11

Joachim Isaksson


The standard time has been adopted by the US during this year.

1883: U.S. and Canadian railways adopt five standardized time zones to replace the multiplicity of local times in communities across the continent. Everyone would soon be operating on "railroad time."

Source

Wikipedia page about Standard Time

like image 1
darkheir Avatar answered Nov 04 '22 04:11

darkheir