index.js 928 B

123456789101112131415161718192021222324252627282930
  1. import toDate from "../toDate/index.js";
  2. import toInteger from "../_lib/toInteger/index.js";
  3. import requiredArgs from "../_lib/requiredArgs/index.js";
  4. /**
  5. * @name fromUnixTime
  6. * @category Timestamp Helpers
  7. * @summary Create a date from a Unix timestamp.
  8. *
  9. * @description
  10. * Create a date from a Unix timestamp.
  11. *
  12. * ### v2.0.0 breaking changes:
  13. *
  14. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  15. *
  16. * @param {Number} unixTime - the given Unix timestamp
  17. * @returns {Date} the date
  18. * @throws {TypeError} 1 argument required
  19. *
  20. * @example
  21. * // Create the date 29 February 2012 11:45:05:
  22. * var result = fromUnixTime(1330515905)
  23. * //=> Wed Feb 29 2012 11:45:05
  24. */
  25. export default function fromUnixTime(dirtyUnixTime) {
  26. requiredArgs(1, arguments);
  27. var unixTime = toInteger(dirtyUnixTime);
  28. return toDate(unixTime * 1000);
  29. }