13
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
JohnJohnGa
  • 15,446
  • 19
  • 62
  • 87
  • Wonder if it's an issue similar to [this one](http://stackoverflow.com/questions/6841333/why-is-subtracting-these-two-times-in-1927-giving-a-strange-result/6841479#6841479) – Mike Christensen Jan 11 '13 at 16:32
  • @MikeChristensen Looks like, but see my Edit, now I am really confused. I am wondering why the end part of the toString mean.. – JohnJohnGa Jan 11 '13 at 17:26
  • The last part is the offset to UTC (depends on the time zone used) Your location was 8 hours behind UTC at Jan 11 1884, but only 7 hours, 52 minutes, 58 seconds behind before the time zones were standardized. – Joachim Isaksson Jan 11 '13 at 17:28
  • @JoachimIsaksson does it mean that there is no time differences? – JohnJohnGa Jan 11 '13 at 17:29

2 Answers2

13

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
Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
  • 2
    interesting, I can't reproduce the same with C#, can anyone tell which languages implemented that 7,02 s "fix" ? – Paweł Staniec Jan 11 '13 at 16:50
  • @torm I guess the fix can be considered either right or wrong. As I understand it, PST was created on that date, so _technically_ Jan 11 1883 PST was never the actual time at any location anyway, although it may be useful to know what the time was at that time before PST was created. Time zones make my head spin. – Joachim Isaksson Jan 11 '13 at 17:35
  • @JoachimIsaksson sure, I'm just curious why 7,02s (or whatever that value is) and why other languages I know, don't have the same thing. Mainly because, if I understand correctly it means that in java current datetime -200 years should not be equal to C# DateTime -200 years which in some cases may cause problems. – Paweł Staniec Jan 11 '13 at 20:34
  • @torm It's most likely a time zone vs. location issue. Most likely, your clock is set to `PST`, which JohnJohnGa's clock was set to something like `America/Los Angeles`. The time in PST should not see the 7 minute shift, while the time in Los Angeles did. – Joachim Isaksson Jan 12 '13 at 12:34
  • are you sure or just guessing not knowing either the OS nor TimeZone settings ? :) btw my OS TZ is set to CEST, by I created DateTime object using PST, how would you suggest doing it to achieve the time shift ? – Paweł Staniec Jan 12 '13 at 13:15
  • @torm Added an edit, not sure if it answers your question, let me know if it doesn't. – Joachim Isaksson Jan 12 '13 at 13:47
1

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

darkheir
  • 8,844
  • 6
  • 45
  • 66