Are you searching for how do you get a timestamp in JavaScript? Use the following JavaScript code get a timestamp. On almost all current browsers you can use Date.now() to get the UTC timestamp in milliseconds; a notable exception to this is IE8 and earlier.
Timestamp in Milliseconds
1 2 3 | var timeStampInMs = window.performance && window.performance.now && window.performance.timing && window.performance.timing.navigationStart ? window.performance.now() + window.performance.timing.navigationStart : Date.now(); console.log(timeStampInMs, Date.now()); |
To get the timestamp in seconds, you can use:
1 | Math.floor(Date.now() / 1000) |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.