Q:

How to Generate a Timestamp in JavaScript

0

How to Generate a Timestamp in JavaScript

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the Date.now() Method

You can simply use the JavaScript Date.now() method to generate the UTC timestamp in milliseconds (which is the number of milliseconds since midnight Jan 1, 1970).

The following example demonstrates how to get a timestamp and how to convert it back to the human-readable date and time format in JavaScript.

<script>
// Creating a timestamp
var timestamp = Date.now();
console.log(timestamp);
    
// Converting it back to human-readable date and time
var d = new Date(timestamp);
console.log(d);
</script>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to Convert JS Object to JSON String... >>
<< How to Append Values to an Array in JavaScript...