本文介绍了如何将日期转换成整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个日期数组,并且一直在使用map函数进行迭代,但是我无法找出将它们转换成整数的JavaScript代码。
I have an array of dates and have been using the map function to iterate through it, but I can't figure out the JavaScript code for converting them into integers.
这是日期数组:
var dates_as_int = [
"2016-07-19T20:23:01.804Z",
"2016-07-20T15:43:54.776Z",
"2016-07-22T14:53:38.634Z",
"2016-07-25T14:39:34.527Z"
];
推荐答案
var dates = dates_as_int.map(function(dateStr) {
return new Date(dateStr).getTime();
});
=>
[1468959781804, 1469029434776, 1469199218634, 1469457574527]
更新:
ES6版本:
Update:ES6 version:
const dates = dates_as_int.map(date => new Date(date).getTime())
这篇关于如何将日期转换成整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!