JavaScript Epoch & Timestamp Converter
Convert between epoch timestamps and dates for JavaScript. Test conversions instantly, then use the code examples with Date, Intl, and date-fns in your application. All conversions are client-side.
Epoch / Timestamp Converter
Convert between Unix timestamps and human-readable dates. Supports seconds and milliseconds.
Quick Reference
Unix epoch is the number of seconds since January 1, 1970 00:00:00 UTC. Timestamps with 13+ digits are automatically treated as milliseconds. Negative values represent dates before 1970.
How to work with epoch timestamps in JavaScript
Get current epoch: Date.now() returns milliseconds. For seconds: Math.floor(Date.now() / 1000). Epoch to date: new Date(1616000000 * 1000) — JavaScript Date expects milliseconds. Date to epoch: Math.floor(new Date('2024-01-15').getTime() / 1000). Parse ISO string: new Date('2024-01-15T12:00:00Z').getTime() / 1000. Important: JavaScript timestamps are milliseconds (13 digits), while Unix timestamps are seconds (10 digits). Always check which format your API uses.
Date formatting in JavaScript
Native formatting: date.toISOString() returns '2024-01-15T12:00:00.000Z'. Localized: date.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }) returns 'January 15, 2024'. Intl.DateTimeFormat: new Intl.DateTimeFormat('en-US', { dateStyle: 'full', timeStyle: 'long', timeZone: 'America/New_York' }).format(date). For complex formatting, use date-fns: format(date, 'yyyy-MM-dd HH:mm:ss'). Avoid Moment.js in new projects — it's in maintenance mode. Temporal API (Stage 3) will eventually replace Date.
Timezone handling in JavaScript
JavaScript Date is always UTC internally, displayed in local timezone by default. Force UTC display: date.toISOString() or date.toUTCString(). Display in specific timezone: date.toLocaleString('en-US', { timeZone: 'Europe/London' }). Get timezone offset: date.getTimezoneOffset() returns minutes (e.g., -300 for EST). For robust timezone handling, use Intl.DateTimeFormat with timeZone option. In Node.js, process timezone: process.env.TZ = 'UTC'. Store timestamps as UTC epoch in databases, convert to local time for display only.
Frequently Asked Questions
How do I get the current epoch timestamp in JavaScript?
Date.now() returns the current time in milliseconds since Unix epoch. For seconds: Math.floor(Date.now() / 1000). In older environments: new Date().getTime(). Both are equivalent.
Why does JavaScript use milliseconds instead of seconds?
JavaScript's Date object was designed with millisecond precision for animation and timing purposes. Most other systems (Unix, Python, PHP) use seconds. Always divide by 1000 when converting JavaScript timestamps to Unix: Math.floor(Date.now() / 1000).
How do I parse a date string to epoch in JavaScript?
new Date('2024-01-15T12:00:00Z').getTime() / 1000 returns the Unix epoch. For non-ISO formats, parsing is unreliable across browsers — use date-fns parse() or manually construct: new Date(year, month - 1, day).getTime() / 1000. Note: month is 0-indexed in JavaScript.
Related Convert Tools
JSON to Code Generator
Generate typed code from JSON in 8 languages — Go, Python, Java, C#, Dart, Rust, Swift, Kotlin structs and classes
CSS to Tailwind Converter
Convert CSS to Tailwind utility classes instantly — 100+ properties including layout, spacing, typography, borders, and effects
SVG to JSX Converter
Convert SVG to JSX or a React/TypeScript component — camelCase attributes, style objects, forwardRef, memo, props spread
OpenAPI to TypeScript
Convert OpenAPI 3.x and Swagger 2.0 specs to TypeScript interfaces and types with $ref resolution, allOf/oneOf/anyOf, enums, and API operation types