differenceInMilliseconds.js 848 B

123456789101112131415161718192021222324252627282930
  1. import { toDate } from "./toDate.js";
  2. /**
  3. * @name differenceInMilliseconds
  4. * @category Millisecond Helpers
  5. * @summary Get the number of milliseconds between the given dates.
  6. *
  7. * @description
  8. * Get the number of milliseconds between the given dates.
  9. *
  10. * @param laterDate - The later date
  11. * @param earlierDate - The earlier date
  12. *
  13. * @returns The number of milliseconds
  14. *
  15. * @example
  16. * // How many milliseconds are between
  17. * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
  18. * const result = differenceInMilliseconds(
  19. * new Date(2014, 6, 2, 12, 30, 21, 700),
  20. * new Date(2014, 6, 2, 12, 30, 20, 600)
  21. * )
  22. * //=> 1100
  23. */
  24. export function differenceInMilliseconds(laterDate, earlierDate) {
  25. return +toDate(laterDate) - +toDate(earlierDate);
  26. }
  27. // Fallback for modularized imports:
  28. export default differenceInMilliseconds;