Date string conversion to unix timestamp in JavaScript / jQuery

前端 未结 4 1131
一向
一向 2020-12-13 18:09

I have date string in this format:

2009-07-15 00:00:00 - 2009-07-15 08:16:23

Could anyone help me to tweak the date string to unix timesta

4条回答
  •  有刺的猬
    2020-12-13 18:44

    var input = "2009-07-15 00:00:00 - 2009-07-15 08:16:23";
    input = input.split(" - ").map(function (date){
        return Date.parse(date+"-0500")/1000;
    }).join(" - ");
    

    Demo

    Date.parse docs

    Note: This won't work on old browsers since I'm using Array.map, but I think you should easily be able to shim it.

提交回复
热议问题