3

If I enter

new Date('0001-01-01T00:00:00.0000000Z')

into Chrome's console, the output is

Date Mon Jan 01 0001 00:34:08 GMT+0034 (Mitteleuropäische Normalzeit)

Where are the 34:08 minutes coming from? How can I circumvent this?

I'm asking this because to specify "an unknown date long ago", our application writes 01/01/0001 into the database, which shows up as 01/01/0001 00:34 in the UI, which is of course slightly disturbing.

Don't tell me not to use "magic numbers" for things like this, I didn't write the application...

Urs Meili
  • 618
  • 7
  • 19
  • from `GMT+0034` – VLAZ May 26 '21 at 14:39
  • @VLAZ OP is asking about why it's in the OUTPUT. It's not COMING from the output. – RobIII May 26 '21 at 14:42
  • 1
    Javascript formats the date for your local timezone on output. UTC in the year 1 apparently had an offset of 00:34 to CET. – deceze May 26 '21 at 14:43
  • @deceze Then why does it result in `Mon Jan 01 0001 00:19:32 GMT+0019 (Central European Standard Time)` in my console? – RobIII May 26 '21 at 14:46
  • @RobIII and the answer is: because of the time zone. The time zone is "wrong" (well, unexpected) because dates are weird. That would reflect the time zone at year 1 in middle of Europe. So, probably accounting for leap seconds and adjustments. – VLAZ May 26 '21 at 14:46
  • 1
    @Rob Possibly because none of that stuff was *really* defined back in 0001, and the specifications are vague or non-existent, and your browser/OS does something different from OP's. – deceze May 26 '21 at 14:47
  • @deceze I'm not sure what OP is using _exactly_ (could OP chime in?) but I'm on W10 21H1 19043.1023, all updated and Chrome 91.0.4472.77. Same for FF (88.0.1) – RobIII May 26 '21 at 14:49
  • I'm on macOS Safari, and I get `Mon Jan 01 0001 00:53:28 GMT+0053 (CET)` FWIW… – deceze May 26 '21 at 14:50
  • 6
    There are technical answers, but using such dates make no sense. What it is wrong it is to use date functions outside usefulness. – Giacomo Catenazzi May 26 '21 at 14:50
  • 2
    Does this answer your question? [Wrong minutes and seconds in a JavaScript date before year 1925](https://stackoverflow.com/questions/52151878/wrong-minutes-and-seconds-in-a-javascript-date-before-year-1925) – 0stone0 May 26 '21 at 14:52
  • 1
    I don't really see the "why" producing a useful answer. Because the reason is: dates are just weird. That's about it. It doesn't help with showing something sensible. The solution to get "sensible" output is to just substitute the "unknown date" value with...well, something that says "unknown date". `if (date.getUTCFullYear() === 1) return "unknown"; else return date.toLocaleString()` – VLAZ May 26 '21 at 14:55
  • @deceze FWIW: On MacOS Chrome _and_ Safari same: Mon Jan 01 0001 00:19:32 GMT+0019 (Central European Standard Time) – RobIII May 26 '21 at 15:02

1 Answers1

3

Weirdly I was just reading about local time discontinuities last night in this post: https://stackoverflow.com/a/6841479/1772933

Without being able to pinpoint exactly why you're getting 34 minutes, there have been numerous time adjustments (not including daylight savings etc), like this 0:5:52 rollback in Shanghai, 1927: https://www.timeanddate.com/time/change/china/shanghai?year=1927 - nor was that the only one over the last 2 centuries, probably done in the interest of global standardization.

I believe the accumulation of these odd time adjustments might be the reason you're seeing this anomaly in your 0001 year, though I thought this was a locale issue and working in UTC would circumvent it.

Kinglish
  • 23,358
  • 3
  • 22
  • 43