timestamper.online
Back to Guides

How to Handle Unix Timestamps in JavaScript

Handle Unix timestamps in JavaScript/TypeScript/Node.js using the native `Date` object.

1. Get Current Timestamp
javascript
// Get current timestamp (milliseconds)
const tsMs = Date.now();

// Get in seconds (for backend/API)
const tsSec = Math.floor(Date.now() / 1000);
2. Convert Date to Timestamp
javascript
const date = new Date('2024-01-01T00:00:00Z');
const ts = Math.floor(date.getTime() / 1000);
3. Convert Timestamp to Readable Date
javascript
const ts = 1704067200;
const date = new Date(ts * 1000);
console.log(date.toISOString());

Need to convert a specific timestamp right now?

Use Online Converter