getUnixTime.js 590 B

12345678910111213141516171819202122232425
  1. import { toDate } from "./toDate.js";
  2. /**
  3. * @name getUnixTime
  4. * @category Timestamp Helpers
  5. * @summary Get the seconds timestamp of the given date.
  6. *
  7. * @description
  8. * Get the seconds timestamp of the given date.
  9. *
  10. * @param date - The given date
  11. *
  12. * @returns The timestamp
  13. *
  14. * @example
  15. * // Get the timestamp of 29 February 2012 11:45:05 CET:
  16. * const result = getUnixTime(new Date(2012, 1, 29, 11, 45, 5))
  17. * //=> 1330512305
  18. */
  19. export function getUnixTime(date) {
  20. return Math.trunc(+toDate(date) / 1000);
  21. }
  22. // Fallback for modularized imports:
  23. export default getUnixTime;