index.js 696 B

1234567891011121314151617181920212223
  1. import getTime from "../getTime/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name getUnixTime
  5. * @category Timestamp Helpers
  6. * @summary Get the seconds timestamp of the given date.
  7. *
  8. * @description
  9. * Get the seconds timestamp of the given date.
  10. *
  11. * @param {Date|Number} date - the given date
  12. * @returns {Number} the timestamp
  13. * @throws {TypeError} 1 argument required
  14. *
  15. * @example
  16. * // Get the timestamp of 29 February 2012 11:45:05 CET:
  17. * const result = getUnixTime(new Date(2012, 1, 29, 11, 45, 5))
  18. * //=> 1330512305
  19. */
  20. export default function getUnixTime(dirtyDate) {
  21. requiredArgs(1, arguments);
  22. return Math.floor(getTime(dirtyDate) / 1000);
  23. }