I want to turn the string 1822-01-01 00:00:00
into a date by:
var d= new Date("1822-01-01 00:00:00");
What I expect using d.toLocaleString()
is 1.1.1822, 00:00:00
, but what I get is 31.12.1821, 23:53:28
.
See fiddle: https://jsfiddle.net/f1kLpfgd/
Javascript Date string constructing wrong date explains the wrong date with time zones. I have a different problem, as even minutes and seconds differ from my input. The solution using the new Date(1822, 0, 1, 0, 0, 0, 0)
constructor does not work for me, as the result is 31.12.1821, 23:53:28
.
Is it because the year is before 1901? But even 1899 works perfectly fine...
Update
For the formatting example custom VS toLocaleString, see updated fiddle: https://jsfiddle.net/f1kLpfgd/8/