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)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
node v10 and later: you should be using
process.hrtime.bigint(), which yields a single BigInt number rather than an array.process.hrtime()has been marked "legacy"Older than node v10: As stated by vaughan,
process.hrtime()is available within Node.js – its resolution are nanoseconds and therefore its much higher. This function returns an array[seconds, nanoseconds]containing the current real-time high-resolution value, but note that it is not tied to any specific clock, meaning the difference in two successive values tells you how much time passed, but individual values tell you nothing meaningful.Other JS environments:
new Date().getTime()? This gives you a timestamp in milliseconds.Update: