WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to Generate a Timestamp in JavaScript

Topic: JavaScript / jQueryPrev|Next

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 will show you how to get a timestamp and how to convert it back to 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>

The Date.now() method is supported in all major web browsers. See the tutorial on JavaScript date and time to learn more about date and time formatting in JavaScript.


Related FAQ

Here are some more FAQ related to this topic:

Your Feedback:

We would love to hear from you, please drop us a line.