Convert between Unix timestamps and human-readable dates. Get current timestamp, format, and parse dates.
import { timestamp } from 'toolmetry';| Function | Parameters | Returns | Description |
|---|---|---|---|
timestamp.now | — | number | Get current Unix timestamp in seconds |
timestamp.toDate | ts: number | string | Convert Unix timestamp to ISO date string |
timestamp.fromDateString | dateStr: string | number | Convert date string to Unix timestamp |
timestamp.format | ts: number, format?: string | string | Format timestamp (iso, utc, locale, date, time) |
import { timestamp } from 'toolmetry';
const now = timestamp.now();
// 1717400000import { timestamp } from 'toolmetry';
const date = timestamp.toDate(1717400000);
// "2024-06-03T06:13:20.000Z"import { timestamp } from 'toolmetry';
const ts = timestamp.fromDateString('2024-06-03');
// 1717372800import { timestamp } from 'toolmetry';
const utc = timestamp.format(1717400000, 'utc');
// "Mon, 03 Jun 2024 06:13:20 GMT"