Unix Timestamp in TypeScript
Look up the current epoch time and convert between Unix seconds and UTC dates in TypeScript.
Get the current timestamp
const nowSeconds: number = Math.floor(Date.now() / 1000);
console.log(nowSeconds);Timestamp to date
const epochSeconds: number = 1_700_000_000;
console.log(new Date(epochSeconds * 1000).toISOString());Date to timestamp
const parsedMilliseconds: number = Date.parse("2023-11-14T22:13:20Z");
console.log(Math.floor(parsedMilliseconds / 1000));Open 1700000000 in the converter
Current Unix time
Seconds—
Milliseconds—
- UTC
- —
- My time zone
- —
Free to use. Your input stays in this browser.
How to use it
- Copy the current-time example into your TypeScript environment to read Unix seconds.
- Run the second example to display 1700000000 as a UTC date.
- Run the last example to convert that date back into seconds.
The number type does not distinguish seconds from milliseconds. Name variables for their units and check Date.parse for NaN when accepting arbitrary text.