Epoch & Unix Timestamp in TypeScript

Get the current epoch timestamp

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

Convert epoch to date

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

Convert date to epoch

const epochSeconds: number = Math.floor(new Date('2026-06-12T00:00:00Z').getTime() / 1000);

TypeScript notes

Same runtime behaviour as JavaScript: Date works in milliseconds. For exhaustive unit handling, model units in the type system, e.g. type EpochSeconds = number & { __brand: 'sec' }.

Check any value live with the epoch converter, or read what Unix time actually counts.

Other languages

C · C# · C++ · Dart · Go · Java · JavaScript · Kotlin · MySQL · Perl · PHP · PostgreSQL · Python · R · Ruby · Rust · Scala · SQLite · Swift