Convert JSON dates without timezone Convert JSON dates without timezone json json

Convert JSON dates without timezone


The problem is that new Date() takes the local time on the clients computer in consideration

Nope. Creating a new Date using the timestamp constructor takes a UTC time stamp.

For example on my machine in UTC+1:

new Date(0)   // Thu Jan 01 1970 01:00:00 GMT+0100 (CET)

OK, the default toString displays this date as 01:00:00 which looks wrong, but that's actually the correct time. 01:00:00 in UTC+1 is 00:00:00 in UTC, which is the moment described by timestamp 0.

If you want to display the dates you've creating from a timestamp in UTC, use date.toUTCString() or fetch and format the consistuent parts of the date using getUTCFullYear(), getUTCMonth() etc.

Please, though, no eval.

new Date(parseInt(jsonDate.slice(6, -1), 10))