Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to get current time in nanoseconds using JavaScript?

So, I know I can get current time in milliseconds using JavaScript. But, is it possible to get the current time in nanoseconds instead?

like image 459
Carlos Melo Avatar asked May 14 '11 15:05

Carlos Melo


People also ask

How much time is a nanosecond?

A nanosecond (ns or nsec) is one billionth (10-9) of a second and is a common measurement of read or write access time to random access memory (RAM). Admiral Grace Hopper famously handed out foot-long lengths of wire to students to illustrate how far an electrical signal can travel in a nanosecond.

How do you write milliseconds in JavaScript?

JavaScript - Date getMilliseconds() Method Javascript date getMilliseconds() method returns the milliseconds in the specified date according to local time. The value returned by getMilliseconds() is a number between 0 and 999.

What is JavaScript date now ()?

now() The static Date. now() method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.

What is timestamp in JavaScript?

A Timestamp represents a point in time independent of any time zone or calendar, represented as seconds and fractions of seconds at nanosecond resolution in UTC Epoch time.


1 Answers

Achieve microsecond accuracy in most browsers using:

window.performance.now() 

See also:

  • https://developer.mozilla.org/en-US/docs/Web/API/Performance.now()
  • http://www.w3.org/TR/hr-time/
  • https://caniuse.com/high-resolution-time
like image 102
Jeffrey Yasskin Avatar answered Sep 22 '22 11:09

Jeffrey Yasskin