Get epoch or Unix timestamp in JavaScript
We can get current epoch or unix timestamp in JavaScript using Date() objects and getTime()
function.
Advertisements
The getTime()
function returns timestamp in milliseconds. We can get current unix timestamp in seconds using below code.
var date = new Date(); var timestamp = Math.floor(date.getTime()/1000.0); console.log(timestamp); //1601529050