Skip to content

convertUnixToUtc

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

Convert a unix epoch value to a UTC Instant ISO string.

  • Converts to UTC Instant using Temporal.Instant.
  • value is a safe integer or a string of optionally negative ASCII digits; anything else, or an instant outside the Temporal range, returns "".
  • An explicit undefined options is the same as omitted; a non-object options (such as a bare "seconds" string) returns "".
ParameterTypeDescription
valuestring | numberepoch value: a safe integer or a digit string

options

optional: how value is read

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 "".

UTC Instant string or "" on invalid

import { convertUnixToUtc } from "@northguild/gmt/unix/convert";
convertUnixToUtc(1709164800000) // "2024-02-29T00:00:00Z"
output 

unix/convert/convertUnixToUtc.ts