JavaScript: Date object to timestamp
3 March 2024 (Updated 18 May 2025)
function dateToUnixTimestamp(date: Date): number {
return Math.floor(date.getTime() / 1000);
}
// Example usage
const myDate = new Date(); // Create a Date instance for the current time
const unixTimestamp = dateToUnixTimestamp(myDate);
console.log(unixTimestamp); // Outputs the UNIX timestamp for `myDate`