How to convert a GMT timestamp to Unix timestamp (javascript)

匿名 (未验证) 提交于 2019-12-03 09:14:57

问题:

I'm parsing an rss feed and each entry has a timestamp such as this: 2009-09-21T21:24:43+04:00 Is there any way to convert this date format to a unix timestamp with javascript?

I just want to be able to record the latest rss entry date, but I need to standardize the time to GMT time or Unix timestamp to do this.

回答1:

The format appears to be ISO-8601. Assuming that is true, this blog provides a javascript solution to this.



回答2:

As I met the same problem, the solution involving Google Closure Library would be:

var pattern = "yyyy-MM-ddTHH:mm:ssZZZZZ"; parser = goog.i18n.DateTimeParse(pattern); var d = new Date(); parser.parse("2009-09-21T21:24:43+04:00", d); unixTime = d.getTime(); 


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