How can I convert a date into an integer?

后端 未结 4 1604
孤街浪徒
孤街浪徒 2021-02-02 05:48

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.

This

4条回答
  •  眼角桃花
    2021-02-02 06:11

    var dates = dates_as_int.map(function(dateStr) {
        return new Date(dateStr).getTime();
    });
    

    =>

    [1468959781804, 1469029434776, 1469199218634, 1469457574527]
    

    Update: ES6 version:

    const dates = dates_as_int.map(date => new Date(date).getTime())
    

提交回复
热议问题