Unix Timestamp in JavaScript

Modern JS has `Date` built-in. For complex timezone or formatting work, use `dayjs` (2KB) or `luxon` (heavier but full-featured).

Common Operations

Get current Unix timestamp (milliseconds)

const ts = Date.now();
// 1706745600000

Get current Unix timestamp (seconds)

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

Convert Unix timestamp to Date

// Date constructor takes milliseconds!
const date = new Date(1706745600 * 1000);
// 'Wed Jan 31 2024 22:40:00 GMT+0000'

Convert Date to Unix timestamp

const ts = Math.floor(new Date('2024-01-31T22:40:00Z').getTime() / 1000);
// 1706740800

Format as ISO 8601 (UTC)

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

Parse ISO 8601 string

const date = new Date('2024-01-31T12:00:00Z');
console.log(date.getTime());
// 1706702400000

Other Languages

Need the full converter? Open the Timestamp Converter →