getTime.mjs 821 B

1234567891011121314151617181920212223242526272829
  1. import { toDate } from "./toDate.mjs";
  2. /**
  3. * @name getTime
  4. * @category Timestamp Helpers
  5. * @summary Get the milliseconds timestamp of the given date.
  6. *
  7. * @description
  8. * Get the milliseconds timestamp of the given date.
  9. *
  10. * @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).
  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.123:
  18. * const result = getTime(new Date(2012, 1, 29, 11, 45, 5, 123))
  19. * //=> 1330515905123
  20. */
  21. export function getTime(date) {
  22. const _date = toDate(date);
  23. const timestamp = _date.getTime();
  24. return timestamp;
  25. }
  26. // Fallback for modularized imports:
  27. export default getTime;