Skip to content

fromSeconds

Creates a Date from a timestamp in seconds.

Use this when receiving a timestamp from a backend that sends seconds (e.g. Java Instant.getEpochSecond()). No heuristic — the input is always treated as seconds.

Available since v2.0.0

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

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

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

View source on GitHub