Parse RSS pubDate to Date object in JavaScript

≡放荡痞女 提交于 2019-12-09 18:41:49

问题


How would I do this?

Tue, 2 Feb 2010 19:34:21 Etc/GMT


回答1:


It works right out of the box. The Date object in JavaScript can be set by passing a number of standard time formats. The format used in RSS is one of these.

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);


来源:https://stackoverflow.com/questions/2191121/parse-rss-pubdate-to-date-object-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!