fromUnixTime.mjs 626 B

12345678910111213141516171819202122232425
  1. import { toDate } from "./toDate.mjs";
  2. /**
  3. * @name fromUnixTime
  4. * @category Timestamp Helpers
  5. * @summary Create a date from a Unix timestamp.
  6. *
  7. * @description
  8. * Create a date from a Unix timestamp (in seconds). Decimal values will be discarded.
  9. *
  10. * @param unixTime - The given Unix timestamp (in seconds)
  11. *
  12. * @returns The date
  13. *
  14. * @example
  15. * // Create the date 29 February 2012 11:45:05:
  16. * const result = fromUnixTime(1330515905)
  17. * //=> Wed Feb 29 2012 11:45:05
  18. */
  19. export function fromUnixTime(unixTime) {
  20. return toDate(unixTime * 1000);
  21. }
  22. // Fallback for modularized imports:
  23. export default fromUnixTime;