0

我有一个像 2012-08-09T20:37:52.041 这样的日期,我想从当前时间中减去这个时间。要使用 getTime() 函数并以可解析的格式减去我这次需要的时间。我怎么做?或者有没有其他方法可以从当前时间中减去像 2012-08-09T20:37:52.041 这样的时间?

4

2 回答 2

2

使用像http://www.datejs.com/这样的日期解析库。有了它,你可以这样做:

Date.parse('2012-08-09T20:37:52') // You'll have to remove the milliseconds
于 2013-08-06T15:47:27.543 回答
1

在 JavaScript 中解析日期真的超级难。

var datestring = "2012-08-09T20:37:52.041";
var date = new Date(datestring);
var diff = (new Date()).getTime() - date.getTime(); // in milliseconds

我在开玩笑,这非常容易。

于 2013-08-06T15:45:50.843 回答