Javascript equivalent of php's strtotime()?

后端 未结 8 1239
無奈伤痛
無奈伤痛 2020-11-27 19:33

In PHP, you can easily convert an English textual datetime description into a proper date with strtotime().

Is there anything similar in Javascript?

8条回答
  •  無奈伤痛
    2020-11-27 19:59

    Browser support for parsing strings is inconsistent. Because there is no specification on which formats should be supported, what works in some browsers will not work in other browsers.

    Try Moment.js - it provides cross-browser functionality for parsing dates:

    var timestamp = moment("2013-02-08 09:30:26.123");
    console.log(timestamp.milliseconds()); // return timestamp in milliseconds
    console.log(timestamp.second()); // return timestamp in seconds
    

提交回复
热议问题