Skip to content

fromMillis

Creates a Date from a timestamp in milliseconds.

Use this when receiving a timestamp from a JS-native source (e.g. Date.now(), performance.timeOrigin). No heuristic — the input is always treated as milliseconds.

Available since v2.0.0

import { fromMillis } from '@helpers4/date';
// or, from the all-in-one package (same code, one install):
import { fromMillis } from 'helpers4/date';
fromMillis(ms: number): Date | null
ParameterTypeDescription
msnumberMilliseconds since the Unix epoch

Date | null — A valid Date, or null for NaN / non-finite input

fromMillis(1737288000000) // => Date('2025-01-19T12:00:00Z')
fromMillis(0)             // => Date('1970-01-01T00:00:00Z')
fromMillis(NaN)           // => null

View source on GitHub