Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript event timestamps not consistent

I notice that when I click one element on my site e.timeStamp is reported by Firebug in the event handler as a 9-digit number, like 866523917, and when I click a different element e.timeStamp is reported in that handler by Firebug as a 16-digit number, like 1376344365954000. Why the difference?

Thanks

like image 548
Steve Avatar asked Aug 12 '13 22:08

Steve


People also ask

What is Event_timestamp?

timeStamp. The timeStamp read-only property of the Event interface returns the time (in milliseconds) at which the event was created.

What is timestamp 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. It is encoded using the Proleptic Gregorian Calendar which extends the Gregorian calendar backwards to year one.

How do I get a timestamp from a date?

Getting the Current Time Stamp If you instead want to get the current time stamp, you can create a new Date object and use the getTime() method. const currentDate = new Date(); const timestamp = currentDate. getTime(); In JavaScript, a time stamp is the number of milliseconds that have passed since January 1, 1970.

How do you do a timestamp in HTML?

The timeStamp Event property is used to get the timestamp of when a particular event is created. It basically returns the difference in time (in milliseconds) between the time of event created by the browser and January 1, 1970. It is a read-only property.


1 Answers

As defined in standard timeStamp returns number of milliseconds since epoch:

Used to specify the time (in milliseconds relative to the epoch) at which the event was created. Due to the fact that some systems may not provide this information the value of timeStamp may be not available for all events. When not available, a value of 0 will be returned.

However, there is no strict definition for epoch:

Examples of epoch time are the time of the system start or 0:0:0 UTC 1st January 1970.

Some events are using first variant (system start) while others use time since 1970. Hence the difference. As a side note it's possible that timeStamp is not provided at all for some events, then its value will be 0.

like image 70
Petr Abdulin Avatar answered Sep 29 '22 18:09

Petr Abdulin