getUnixTime.cjs 578 B

123456789101112131415161718192021222324
  1. "use strict";
  2. exports.getUnixTime = getUnixTime;
  3. var _index = require("./toDate.cjs");
  4. /**
  5. * @name getUnixTime
  6. * @category Timestamp Helpers
  7. * @summary Get the seconds timestamp of the given date.
  8. *
  9. * @description
  10. * Get the seconds timestamp of the given date.
  11. *
  12. * @param date - The given date
  13. *
  14. * @returns The timestamp
  15. *
  16. * @example
  17. * // Get the timestamp of 29 February 2012 11:45:05 CET:
  18. * const result = getUnixTime(new Date(2012, 1, 29, 11, 45, 5))
  19. * //=> 1330512305
  20. */
  21. function getUnixTime(date) {
  22. return Math.trunc(+(0, _index.toDate)(date) / 1000);
  23. }