我有一个类似 1331209044000 的时间戳,我想将其转换为ISO 8601时间戳.如何使用JavaScript进行转换?
I have a timestamp like this 1331209044000 and I want to convert it to an ISO 8601 timestamp. How can I convert it using JavaScript?
我使用jQuery的"timeago"插件- timeago.yarp/
I use the jQuery "timeago" plugin - timeago.yarp/
推荐答案假设您的时间戳以毫秒为单位(或者您可以轻松地转换为毫秒),则可以使用 Date 构造函数和 date.toISOString()方法.
Assuming your timestamp is in milliseconds (or you can convert to milliseconds easily) then you can use the Date constructor and the date.toISOString() method.
var s = new Date(1331209044000).toISOString(); s; // => "2012-03-08T12:17:24.000Z"如果您针对不支持EMCAScript 5th Edition的旧版浏览器,则可以使用此问题中列出的策略:如何在JavaScript中输出ISO 8601格式的字符串?
If you target older browsers which do not support EMCAScript 5th Edition then you can use the strategies listed in this question: How do I output an ISO 8601 formatted string in JavaScript?
更多推荐
如何在JavaScript中将Unix时间戳转换为ISO 8601?
发布评论