Get epoch for a specific date using Javascript

后端 未结 7 1741
清歌不尽
清歌不尽 2020-12-08 08:42

How do I convert 07/26/2010 to a UNIX timestamp using Javascript?

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 09:35

    Date.parse() method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC.

    const unixTimeZero = Date.parse('01 Jan 1970 00:00:00 GMT');
    const javaScriptRelease = Date.parse('04 Dec 1995 00:12:00 GMT');
    
    console.log(unixTimeZero);
    // expected output: 0
    
    console.log(javaScriptRelease);
    // expected output: 818035920000
    

    Explore more at: Date.parse()

提交回复
热议问题