1

I've got this following string from JSON API:

"Date": "\/Date(1381446000000+0100)\/",

which should be:

2013-10-11 00:00:00

but instead I get this:

2013-10-10T23:00:00.000Z

My code:

new Date(parseFloat(oldDate.replace("/Date(", "").replace(")/", ""))); 
Jonathan
  • 3,016
  • 9
  • 43
  • 74
  • possible duplicate of [Parsing Date from webservice](http://stackoverflow.com/questions/11024367/parsing-date-from-webservice) or [Javascript Date from milliseconds and timezone](http://stackoverflow.com/questions/13614792/javascript-date-from-milliseconds-and-timezone) – Bergi Oct 14 '13 at 20:17
  • Already had a look at those links and tried their solutions but none of them worked – Jonathan Oct 14 '13 at 20:22

1 Answers1

2

Try This :

var date = "/Date(1381446000000+0100)/";
var d = new Date(parseFloat(date.replace("/Date(", "").replace(")/", "")));
  • This answer ignores the offset so the time will be wrong unless the offset was `+0000` – Jon Adams Jun 12 '18 at 01:14
  • @JonAdams—do you have a reference to documentation for how the offset should be treated (genuine request)? Does [this answer](https://stackoverflow.com/a/13637479/257182) handle it correctly? – RobG Apr 07 '20 at 10:33
  • @RobG Yes, https://stackoverflow.com/a/13637479/2291 looks acceptable. – Jon Adams Apr 07 '20 at 12:55
  • @JonAdams—so no documentation? I'd like to find something that looks official on how to create it or parse it. It seems to be treated as if the first number is a millisecond offset from the epoch in the source location, and that the offset is HHmm and has to be applied to get UTC. So in this case `new Date(1381446000000 - 3.6e6).toISOString()` which gives 2013-10-10T22:00:00.000Z, Is that correct? – RobG Apr 07 '20 at 13:33