How to get a timestamp with JavaScript

How to get a timestamp with JavaScript

·

1 min read

Photo by insung yoon

A timestamp is a numerical value that represents the amount of time that has passed since the Unix epoch (1st Jan 1970) and you get the number of ​milliseconds ​since then with the Date.now() ​function in JavaScript.

So you might want to divide this by 1000 and round it to get the number of seconds which is more commonly used for timestamps.

Date​.​now​(); // Milliseconds
Math​.​round​(​Date​.​now​()​ ​/​ ​1000​); // Seconds

Watch the tutorial for more details.

Follow me on Twitter (@codebubb) for more tutorials.