简体   繁体   English

如何将GMT时间戳转换为Unix时间戳(javascript)

[英]How to convert a GMT timestamp to Unix timestamp (javascript)

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? 我正在解析rss供稿,每个条目都有这样的时间戳:2009-09-21T21:24:43 + 04:00有没有办法用JavaScript将这种日期格式转换为unix时间戳?

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. 我只想能够记录最新的rss输入日期,但是我需要将时间标准化为GMT时间或Unix时间戳来执行此操作。

As I met the same problem, the solution involving Google Closure Library would be: 当我遇到相同的问题时,涉及Google Closure库的解决方案将是:

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

The format appears to be ISO-8601. 格式似乎是ISO-8601。 Assuming that is true, this blog provides a javascript solution to this. 假设是真的, 此博客为此提供了一个javascript解决方案。

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

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