标签云

微信群

扫码加入我们

WeChat QR Code

Possible Duplicate:How to format a JSON date?I have the following result from a $getJSON call from JavaScript.How do I convert the start property to a proper date in JavaScript?[{"id":1,"start":"/Date(1238540400000)/"},{"id":2,"start":"/Date(1238626800000)/"}]Thanks!


"1238540400000" what's this? Milliseconds since the year 1970?

2019年07月24日35分27秒

Meeh : yup, the number milliseconds since 1970/01/01

2019年07月23日35分27秒

You could use JSON++ instead of JSON. JSON++is the same than JSON but with support for JavaScript types such as Date.

2019年07月23日35分27秒

Don't * 1 to convert a string to a number. Use parseInt(number, 10). Also, if you want a cool trick like * 1, just try +str to make it a number.

2019年07月23日35分27秒

Greg I want a short date instead of "Thu Apr 26 2018 14:39:28 GMT+0700 (SE Asia Standard Time)"

2019年07月24日35分27秒

This wouldn't account for the closing ')/'

2019年07月24日35分27秒

The parseInt function parses only until it founds legal characters for int, then it stops. The closing ')/' will not be parsed.

2019年07月23日35分27秒

Cool, but that doesn't sound very robust:P

2019年07月23日35分27秒

It is robust, in that it works every time, in all situations

2019年07月23日35分27秒

J.T.Taylor Yes indeed, I just wanted to mitigate your affirmation : "it works every time, in all situations"

2019年07月23日35分27秒

thanks for the blog...I think you need to add "Z?" to the regex for matching the date otherwise we fail to match non-UTC dates.

2019年07月24日35分27秒

Thanks a ton for this! Great post!

2019年07月24日35分27秒

Actually more like myDate = new DateTime(1970, 1, 1).AddMilliseconds(jsonDateVal);

2019年07月24日35分27秒