How to get a timestamp in JavaScript

Below are the ways to get a timestamp in Javascript.

Date.now returns the UTC timestamp in milliseconds.

If you are using IE you can use the below code.

if (!Date.now) {
    Date.now = function now() {
        return new Date().getTime();
    };
}
To convert the timestamp in seconds use below code

Math.floor(Date.now() / 1000)

No comments:

Post a Comment

Please Provide your feedback here