Menu

gitpiper

getTimestamp javascript Code Snippet in 2024

datebeginner

Last Updated: 3 December 2024

Gets the Unix timestamp from a Date object.

  • Use Date.prototype.getTime() to get the timestamp in milliseconds and divide by 1000 to get the timestamp in seconds.
  • Use Math.floor() to appropriately round the resulting timestamp to an integer.
  • Omit the argument, date, to use the current date.
const getTimestamp = (date = new Date()) => Math.floor(date.getTime() / 1000);
getTimestamp(); // 1602162242

javascript snippet similar to getTimestamp For You in December 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️