getTime.js 803 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. exports.getTime = getTime;
  3. var _index = require("./toDate.js");
  4. /**
  5. * @name getTime
  6. * @category Timestamp Helpers
  7. * @summary Get the milliseconds timestamp of the given date.
  8. *
  9. * @description
  10. * Get the milliseconds timestamp of the given date.
  11. *
  12. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  13. *
  14. * @param date - The given date
  15. *
  16. * @returns The timestamp
  17. *
  18. * @example
  19. * // Get the timestamp of 29 February 2012 11:45:05.123:
  20. * const result = getTime(new Date(2012, 1, 29, 11, 45, 5, 123))
  21. * //=> 1330515905123
  22. */
  23. function getTime(date) {
  24. const _date = (0, _index.toDate)(date);
  25. const timestamp = _date.getTime();
  26. return timestamp;
  27. }