JavaScript Get Timestamp


JavaScript Get Timestamp: You can use Date.now() to get the UTC Timestamp in milliseconds. Date.now() Works for all major browsers. Here in this tutorial we are going to explain how to get current timestamp in javaScript. We will also learn how to use the timestamp in javaScript.


JavaScript Get Timestamp

Here is simple example which will give you timestamp in javascript-

JavaScript Get Timestamp:

<script type="text/javascript">
document.write("Current Date = "+Date()+"<br>");
document.write("Current TimeStamp = "+Date.now());
</script>

Try it »

In the above example we have shown how to get current date and timestamp in javascript. The UTC timestamp shown above will work in all modern browsers.

Note :For older browsers use Date().getTime() instead of using Date.now().

The output of the above example will look something like this –

JavaScript Get Timestamp

More About JavaScript Timestamp

Let’s have look over the JavaScript time & Date with more example and demo here.

Convert UTC date time to local date time in JavaScript

You can convert the UTC time to local date time as below-

Convert UTC date time to local date time in JavaScript:

<html>
<head>
<script type="text/javascript">
function localizeTime(currTime)
{
  var dt=new Date(currTime+" UTC");
  document.write("After Conversion = "+dt.toString());
}
</script>
</head>
<body>
<script type="text/javascript">
 document.write("Time Before Conversion = "+Date()+"<br>");
localizeTime(Date());
</script>
</body>
</html>

Try it »

The above example will give you the converted time local time from the UTC. When you run the above demo it will produce the output like this-

JavaScript Get Timestamp


Advertisements

Add Comment

📖 Read More