Timestamp Converter

Conversion

Convert between Unix timestamps and human-readable dates. Get current timestamp, format, and parse dates.

Import

import { timestamp } from 'toolmetry';

API Reference

FunctionParametersReturnsDescription
timestamp.nownumberGet current Unix timestamp in seconds
timestamp.toDatets: numberstringConvert Unix timestamp to ISO date string
timestamp.fromDateStringdateStr: stringnumberConvert date string to Unix timestamp
timestamp.formatts: number, format?: stringstringFormat timestamp (iso, utc, locale, date, time)

Examples

Current Timestamp
import { timestamp } from 'toolmetry';

const now = timestamp.now();
// 1717400000
Timestamp to Date
import { timestamp } from 'toolmetry';

const date = timestamp.toDate(1717400000);
// "2024-06-03T06:13:20.000Z"
Date to Timestamp
import { timestamp } from 'toolmetry';

const ts = timestamp.fromDateString('2024-06-03');
// 1717372800
Format Timestamp
import { timestamp } from 'toolmetry';

const utc = timestamp.format(1717400000, 'utc');
// "Mon, 03 Jun 2024 06:13:20 GMT"