How do you get a timestamp in JavaScript?

前端 未结 30 3078
情深已故
情深已故 2020-11-21 15:19

How can I get a timestamp in JavaScript?

Something similar to Unix timestamp, that is, a single number that represents the current time and date. Either as a number

30条回答
  •  说谎
    说谎 (楼主)
    2020-11-21 15:37

    For a timestamp with microsecond resolution, there's performance.now:

    function time() { 
      return performance.now() + performance.timing.navigationStart;
    }
    

    This could for example yield 1436140826653.139, while Date.now only gives 1436140826653.

提交回复
热议问题