简体   繁体   English

将时间转换为ISO 8601格式

[英]Converting time to ISO 8601 format

I'm reading from a RSS feed which outputs date/time in the following format: 我正在阅读RSS提要,该提要以以下格式输出日期/时间:

Day, DD Mon YYYY HH:MM:SS OFFSET 日,DD周一YYYY HH:MM:SS偏移

For example, 例如,

Tue, 24 Apr 2012 08:15:00 -0700 2012年4月24日,星期二08:15:00 -0700

Using JavaScript,I need to convert it to an ISO8601 string (via Date.toISOString() preferably). 使用JavaScript,我需要将其转换为ISO8601字符串(最好通过Date.toISOString() )。

Any assistance would be appreciated. 任何援助将不胜感激。

I haven't really worked with time in JS before, so I haven't got many ideas. 我以前从来没有真正在JS中工作过,所以我没有很多想法。 Would it be possible to switch the offset to a time zone, and convert it as a JS Date object? 是否可以将偏移量切换到时区,并将其转换为JS Date对象?

u can do that with the date object (at least it is working for me in chrome) 您可以使用date对象(至少在chrome中对我有用)

var test = new Date("Tue, 24 Apr 2012 08:15:00 -0700");
test.toISOString() // "2012-04-24T15:15:00.000Z"

I hope it is the correct output... not sure 我希望它是正确的输出...不确定

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

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