How to get a microtime in Node.js?

后端 未结 13 1196
情深已故
情深已故 2020-12-04 13:41

How can I get the most accurate time stamp in Node.js?

ps My version of Node.js is 0.8.X and the node-microtime extension doesn\'t work for me (crash on install)

13条回答
  •  佛祖请我去吃肉
    2020-12-04 14:28

    new Date().getTime()? This gives you a timestamp in milliseconds, which is the most accurate that JS will give you.

    Update: As stated by vaughan, process.hrtime() is available within Node.js - its resolution are nanoseconds and therefore its much higher, also this doesn't mean it has to be more exact.

    PS.: Just to be clearer, process.hrtime() returns you a tuple Array containing the current high-resolution real time in a [seconds, nanoseconds]

提交回复
热议问题