JavaScript: Date object to timestamp
3 March 2024 (Updated 3 March 2024)
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`
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment