Date
object.Date.prototype.getTime()
to get the timestamp in milliseconds and divide by 1000
to get the timestamp in seconds.Math.floor()
to appropriately round the resulting timestamp to an integer.date
, to use the current date.const getTimestamp = (date = new Date()) => Math.floor(date.getTime() / 1000);
getTimestamp(); // 1602162242
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️