Skip to content

parseDateFromUnix

parseDateFromUnix(value: string | number, options?: { epochUnit?: UnixUnit; timeZone?: string; }): string

Extract the date portion from a unix epoch value.

  • Converts to ZonedDateTime then extracts the PlainDate.
  • Returns "" for invalid input.
ParameterTypeDescription
valuestring | numberunix epoch in milliseconds or seconds: a safe integer, or a string of optionally negative ASCII digits

options

optional: how value is read and the zone its wall clock is read in

OptionTypeDefaultDescription
epochUnit?"seconds" | "milliseconds" | "second" | "millisecond" (UnixUnit)"milliseconds"The unit the epoch values are counted in: "seconds" or "milliseconds", singular or plural. Any other value returns "".
timeZone?string"UTC"The time zone the wall-clock fields are read in: an IANA name, a UTC offset (a time zone identifier such as +05:30, +0530 or -08, or a stored offset ±HH:MM[:SS], what getTimeZoneOffset returns), or "local" for the system time zone. An unknown zone returns "".

ISO date string (e.g., “2024-03-17”) or "" on invalid input

import { parseDateFromUnix } from "@northguild/gmt/unix/parse";
parseDateFromUnix(1700000000000, { timeZone: "UTC" }) // "2023-11-14"
output 

unix/parse/parseDateFromUnix.ts