如何在JavaScript中将Unix时间戳转换为ISO 8601?

编程入门 行业动态 更新时间:2024-10-27 18:25:07
本文介绍了如何在JavaScript中将Unix时间戳转换为ISO 8601?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个类似 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?

本文发布于:2023-10-23 01:35:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519349.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   中将   时间   如何在   JavaScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!