0

getLocalTime = function () {
  var utcDateStr = document.getElementById('input').innerHTML ;
  var utcDate = new Date(utcDateStr);
  var offset = new Date().getTimezoneOffset() * 60000;
  var localDate = new Date(utcDate.getTime() - offset);
  var localDateStr = localDate.toLocaleString();
  document.getElementById('output').innerHTML =localDateStr;
};
<p id="input">0001-01-01T00:00:00</p>
<p id="output"></p>
<button onclick="getLocalTime()">Click</button>

Here's a jsFiddle, although it will only work if you're currently in GMT+1 timezone.

I think it's possibly similar to this other question, but I couldn't find any further info for GMT.

Durga
  • 15,263
  • 2
  • 28
  • 52
RBII
  • 1
  • 1
  • 2

2 Answers2

1

try adding "Z" at the end of your ISO-string, like this "0001-01-01T00:00:00Z" and then do your thing

new Date("0001-01-01T00:00:00Z") >> Mon Jan 01 0001 01:00:00 GMT+0100 (CET) new Date("0001-01-01T00:00:00") >> Mon Jan 01 0001 00:00:00 GMT+0100 (CET)

Ostoja
  • 119
  • 8
1

There was a 1 minute and 15 second adjustment needed to move Local Mean Time to be in line with GMT (I think) which happened on December 1, 1847 at midnight. So any dates before that are "off" by 1m15.

Source: https://www.timeanddate.com/time/change/uk/london?year=1847

If anyone has any further sources please post the, I can't find any more info from my cursory google search!

Mardoxx
  • 4,372
  • 7
  • 41
  • 67