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(")/", ""))); 
2

1 Answer 1

2

Try This :

var date = "/Date(1381446000000+0100)/";
var d = new Date(parseFloat(date.replace("/Date(", "").replace(")/", "")));
Sign up to request clarification or add additional context in comments.

4 Comments

This answer ignores the offset so the time will be wrong unless the offset was +0000
@JonAdams—do you have a reference to documentation for how the offset should be treated (genuine request)? Does this answer handle it correctly?
@RobG Yes, stackoverflow.com/a/13637479/2291 looks acceptable.
@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?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.