简体   繁体   English

JavaScript时间戳的意外行为

[英]Unexpected behaviour of javascript timestamp

I use phoneGap Geo-location API to get current position in which i got time-stamp also. 我使用phoneGap地理位置API来获取当前位置,在该位置我也获得了时间戳记。

alert(data[0].timestamp);
alert(new Date(data[0].timestamp).getTime());

where data[0].timestamp = "2013-12-03T19:09:58.859Z" 其中data[0].timestamp = "2013-12-03T19:09:58.859Z"

in web browser the second alert shows 1386097798859 whereas when i built and test app in mobile then it alert as NaN I don't understand why it happens? 在Web浏览器中,第二个警报显示1386097798859而当我在移动设备中构建和测试应用程序时,它以NaN警报,我不明白为什么会发生?

It's a ISODate format. 这是ISODate格式。 Try to use Date.parse or use momentjs javascript library which can parse a lot of date formats. 尝试使用Date.parse或使用momentjs javascript ,该可以解析许多日期格式。

Also there is a gist with Date.parse polifyll. 还有一个Date.parse polifyll 要点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM