Javascript equivalent of php's strtotime()?

后端 未结 8 1248
無奈伤痛
無奈伤痛 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 20:00

    Yes, it is. And it is supported in all major browser:

    var ts = Date.parse("date string");
    

    The only difference is that this function returns milliseconds instead of seconds, so you need to divide the result by 1000.

    Check what valid formats can JavaScript parse.

提交回复
热议问题