Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Web Technology by (47.6k points)

How can I get a timestamp in JavaScript?

Something similar to Unix's timestamp, that is, a single number that represents the current time and date. Either as a number or a string.

1 Answer

0 votes
by (106k points)

For getting a timestamp in JavaScript almost all current browsers you can use Date.now()method and it will return the UTC timestamp in milliseconds.

See the code below:-

if (!Date.now) { 

Date.now = function() { 

return new Date().getTime(); 

  } 

}

Related questions

0 votes
1 answer
0 votes
1 answer
asked Dec 29, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Apr 7, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...