How To Get Current Timestamp In JavaScript

All functions for working with date and time in Javascript are in module Date. This module provides multiple ways how you can get current timestamp in JavaScript. Unlike other languages JavaScript provides number of miliseconds elapsed since 1 January 1970 00:00:00 UTC. Other languages provides mostly just number of seconds.

Using Just Constructor

When object Date is created without any parameter it uses current time, so it is possible to get current timestamp with following code:


var ts = new Date().getTime()/1000;
console.log(ts)
# 1505873404.79

Using Date.now()

Object Date also provides function now which also returns number of miliseconds elapsed since beginning of the epoch.


var ts = var ts = Date.now()/1000;
console.log(ts)
# 1505873404.79
This website uses cookies to ensure you get the best experience on our website. More info