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> |
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.
The output of the above example will look something like this –
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> |
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-
Advertisements
Add Comment
📖 Read More
- 1. JavaScript get current url
- 2. Select element by data attribute in JavaScript
- 3. jQuery trigger function when element is in viewport
- 4. Bootstrap change tooltip content on click