Skip to content

convertUtcToUnix

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

Convert a UTC Instant string to a unix epoch value in milliseconds or seconds.

  • Uses Temporal.Instant.from to parse.
  • Seconds floor toward −∞, so "1969-12-31T23:59:59.5Z" is second -1 (POSIX time_t).
  • options must be an object or omitted: a non-object value (such as a bare "seconds" string) returns null.
  • Returns null for invalid input.
ParameterTypeDescription
valuestringUTC Instant string

options

The unit of the returned epoch value

OptionTypeDefaultDescription
epochUnit?"seconds" | "milliseconds" | "second" | "millisecond" (UnixUnit)"milliseconds"The unit the epoch value is returned in: "seconds" or "milliseconds", singular or plural. An explicit undefined is the same as omitted; any other value returns null.

epoch number or null on invalid

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

utc/convert/convertUtcToUnix.ts