Unix Timestamp in TypeScript

Same as JavaScript - use `Date` or `dayjs`. TypeScript adds type safety but no new APIs.

Common Operations

Get current Unix timestamp (typed)

const ts: number = Math.floor(Date.now() / 1000);
// 1706745600

Convert Unix timestamp to Date

const date: Date = new Date(1706745600 * 1000);

Format as ISO 8601

const iso: string = new Date().toISOString();
// '2024-01-31T22:40:00.000Z'

Type-safe ISO 8601 string

type ISODateString = string & { __brand: 'ISODateString' };
function toISO(d: Date): ISODateString {
  return d.toISOString() as ISODateString;
}

Other Languages

Need the full converter? Open the Timestamp Converter →