简体   繁体   English

在JavaScript中将RSS pubDate解析为Date对象

[英]Parse RSS pubDate to Date object in JavaScript

How would I do this? 我该怎么做?

Tue, 2 Feb 2010 19:34:21 Etc/GMT 星期二,2010年2月2日19:34:21等等/ GMT

It works right out of the box. 它开箱即用。 The Date object in JavaScript can be set by passing a number of standard time formats. 可以通过传递多种标准时间格式来设置JavaScript中的Date对象。 The format used in RSS is one of these. RSS中使用的格式就是其中之一。

Example: 例:

var pubDate = "Sun, 27 Mar 2011 20:17:21 +0100";
var date = new Date(pubDate);

var months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var string = date.getDate() + " " + months[date.getMonth()] + " " + date.getFullYear()

alert(string);

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

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