Convert normal date to unix timestamp

前端 未结 11 908
小鲜肉
小鲜肉 2020-11-28 05:10

How can I convert normal date 2012.08.10 to unix timestamp in javascript?

Fiddle: http://jsfiddle.net/J2pWj/




I\'ve se

相关标签:
11条回答
  • 2020-11-28 06:02

    var d = '2016-01-01T00:00:00.000Z';
    console.log(new Date(d).valueOf()); // returns the number of milliseconds since the epoch

    0 讨论(0)
  • 2020-11-28 06:05
    new Date('2012.08.10').getTime() / 1000
    

    Check the JavaScript Date documentation.

    0 讨论(0)
  • 2020-11-28 06:07

    You can do it using Date.parse() Method.

    Date.parse($("#yourCustomDate).val())
    

    Date.parse("03.03.2016") output-> 1456959600000

    Date.parse("2015-12-12") output-> 1449878400000

    0 讨论(0)
  • 2020-11-28 06:09

    convert timestamp to unix timestamp.

    const date = 1513787412; const unixDate = new Date(date * 1000);// Dec 20 2020 (object)

    to get the timeStamp after conversion const TimeStamp = new Date(date*1000).getTime(); //1513787412000

    0 讨论(0)
  • 2020-11-28 06:11

    You can use Date.parse(), but the input formats that it accepts are implementation-dependent. However, if you can convert the date to ISO format (YYYY-MM-DD), most implementations should understand it.

    See Why does Date.parse give incorrect results?.

    0 讨论(0)
提交回复
热议问题