getSeconds.mjs 783 B

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