Gets the Unix timestamp from a 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
JavaScript, Date
Creates a Date
object from a Unix timestamp.
JavaScript, Date
Gets the day of the year (number in the range 1-366) from a Date
object.
JavaScript, Date
Returns a string of the form HH:MM:SS
from a Date
object.