How to Get current Timestamp in JavaScript
Abstract: Get Timestamp in Milliseconds in JavaScript The following JavaScript code will return current timestamp in milliseconds (Total milliseconds since 1970
JavaScript Code: var timeStamp = Math.floor(Date.now() / 1000);
The above command will return current timestamp or epoch time or Unix timestamp in seconds (Total seconds since 1970/01/01).
- Read this => JavaScript ForEach Method
- Get Timestamp in Milliseconds in JavaScript
The following JavaScript code will return current timestamp in milliseconds (Total milliseconds since 1970/01/01) and store in timeStamp variable.
var timeStamp = Math.floor(Date.now());1var timeStamp = Math.floor(Date.now()); - Get Timestamp in Seconds in JavaScript
The following JavaScript code will return current timestamp in seconds (Total seconds since 1970/01/01) and store in timeStamp variable.
var timeStamp = Math.floor(Date.now() / 1000);1var timeStamp = Math.floor(Date.now() / 1000); - Get Date/Time in UTC in JavaScript
The following JavaScript code will create an object of Date and then get current date/time in UTC in human readable for.
var dt = new Date(); var utcDate = dt.toUTCString(); //Print results console.log(utcDate);12345var dt = new Date();var utcDate = dt.toUTCString(); //Print resultsconsole.log(utcDate);The output will be as following:
Wed, 25 Jul 2018 04:44:15 GMT