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
timeStamp. The timeStamp read-only property of the Event interface returns the time (in milliseconds) at which the event was created.
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.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With