Epoch Convert: The Complete Guide to Converting Unix Time (with Code, Tips, and Tools)
Introduction
If you work with logs, APIs, or databases, you meet epoch time a lot. You often need to epoch convert values into readable dates, and back again. Doing this well saves time and avoids bugs. This guide explains the concepts, shows code, and gives best practices.
It is written for humans first. It is also optimized for search, voice, and AI overviews. You will find clear steps, examples, and expert tips.
Featured Snippet: Quick Answer
Epoch convert means changing a Unix timestamp (seconds or milliseconds since 1970-01-01 UTC) into a human-readable date and back. Use a tool like ZenixTools to paste a timestamp, pick seconds or milliseconds, select a timezone, and copy an ISO 8601 or RFC 3339 date. In code, use built-in date functions (JavaScript, Python, SQL) to parse and format reliably.
AI Overview
This guide explains epoch time (Unix timestamps) and how to convert it to readable dates across tools and languages. Learn when to use seconds vs milliseconds, how to handle UTC and time zones, and how to avoid common mistakes like DST shifts or unit mix-ups. Includes a fast ZenixTools workflow, code for JavaScript, Python, SQL, CLI, and Excel, plus best practices, expert tips, a comparison table, and FAQs.
Key Takeaways
- Epoch time counts seconds or milliseconds since 1970-01-01T00:00:00Z (UTC).
- Know your units: seconds (10 digits) vs milliseconds (13 digits) vs microseconds.
- Convert in UTC first, then show local time for users.
- Use ISO 8601 or RFC 3339 for clean, unambiguous output.
- Prefer integers for storage and indexing; document the unit.
- ZenixTools converts epoch to readable dates and back in seconds.
- In code, use standard libraries (JavaScript Date, Python datetime, SQL functions).
- Avoid DST pitfalls, rounding errors, and the 2038 problem on 32-bit systems.
Table of Contents
What is Epoch Convert?
Epoch convert is the act of translating between Unix timestamps and human-readable dates. A Unix timestamp is a count of time since the Unix epoch: 1970-01-01T00:00:00Z, in UTC.
There are several common units:
- Seconds since epoch (10-digit numbers, like 1704067200)
- Milliseconds since epoch (13-digit numbers, like 1704067200000)
- Microseconds or nanoseconds (less common in many apps)
This system is also called POSIX time or Unix time. It ignores leap seconds. Most operating systems and languages rely on it. Many APIs, logs, and databases store timestamps in this form for speed and simplicity.
When you epoch convert, you either:
- Turn a timestamp into a date-time string, such as an ISO 8601 value: 2024-01-01T00:00:00Z.
- Turn a readable date into a timestamp for storage or math.
Related terms you may see include Unix time, timestamp converter, RFC 3339, ISO 8601, UTC offset, timezone, DST, and 64-bit time.
Why It Matters
Good time handling reduces errors and confusion. Here is why it matters:
- Analytics and logging: Readable times speed up debugging and dashboards.
- APIs and webhooks: Many payloads use epoch seconds (for example, JWT exp claims).
- Scheduling and jobs: Cron, queues, and TTLs use timestamps.
- Databases and indexing: Integers sort and filter quickly.
- User experience: Show the right local time, including DST and offsets.
- Compliance and reporting: Clear, traceable dates help audits.
- Structured data: Clear ISO 8601 dates aid search engines and schema consumers.
Benefits
- Simplicity: Epoch timestamps are compact and easy to compare.
- Performance: Integers index and sort fast in databases.
- Portability: Works across OSes and programming languages.
- Clarity: ISO 8601 avoids ambiguous local formats.
- Reliability: UTC-based time avoids local daylight issues in storage.
- Automation: Easy math for durations, TTL, and windows.
Step-by-Step Guide
Use ZenixTools Epoch Converter
Follow this 5-step workflow to convert epoch quickly:
- Open ZenixTools Epoch Converter.
- Paste your timestamp.
- Choose the unit: seconds, milliseconds, or microseconds.
- Select output timezone: UTC or a specific region (e.g., America/New_York).
- Copy the result in ISO 8601 or RFC 3339 format, plus the localized time if needed.
You can also enter a date like 2025-06-15T12:30:00Z and get epoch seconds, milliseconds, and a relative time (for example, in 3 days).
Notes:
- ISO 8601 examples: 2024-09-04T15:00:00Z or 2024-09-04T11:00:00-04:00.
- RFC 3339 is a profile of ISO 8601 used by many APIs.
JavaScript
const tsMs = 1704067200000; // milliseconds
const d = new Date(tsMs);
console.log(d.toISOString()); // '2024-01-01T00:00:00.000Z'
const tsSec = 1704067200;
const d = new Date(tsSec * 1000);
console.log(d.toISOString());
const d = new Date('2024-01-01T00:00:00Z');
const ms = d.getTime(); // milliseconds since epoch
const sec = Math.floor(ms / 1000);
Tip: Use Intl.DateTimeFormat or libraries like date-fns or Luxon for formatting and time zones.
Python
from datetime import datetime, timezone
sec = 1704067200
print(datetime.fromtimestamp(sec, tz=timezone.utc).isoformat())
ms = 1704067200000
print(datetime.fromtimestamp(ms / 1000, tz=timezone.utc).isoformat())
from datetime import datetime, timezone
d = datetime(2024, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
sec = int(d.timestamp())
ms = int(d.timestamp() * 1000)
Tip: Use zoneinfo (Python 3.9+) for time zone conversions.
Bash and CLI
date +%s
- Epoch to UTC date (seconds):
date -u -d @1704067200 '+%Y-%m-%dT%H:%M:%SZ'
ms=1704067200000; date -u -d @$(($ms/1000)) '+%Y-%m-%dT%H:%M:%SZ'
Note: BSD/macOS may use a different date syntax. On macOS:
date -u -r 1704067200 '+%Y-%m-%dT%H:%M:%SZ'
SQL (PostgreSQL, MySQL, BigQuery, SQLite)
-- seconds to timestamptz UTC
SELECT to_timestamp(1704067200) AT TIME ZONE 'UTC';
-- date to epoch seconds
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2024-01-01 00:00:00+00');
-- seconds to datetime UTC
SELECT FROM_UNIXTIME(1704067200);
-- datetime to epoch seconds
SELECT UNIX_TIMESTAMP('2024-01-01 00:00:00');
-- seconds to timestamp
SELECT TIMESTAMP_SECONDS(1704067200);
-- milliseconds to timestamp
SELECT TIMESTAMP_MILLIS(1704067200000);
-- datetime to epoch seconds
SELECT UNIX_SECONDS(TIMESTAMP '2024-01-01 00:00:00+00');
-- seconds to datetime UTC
SELECT datetime(1704067200, 'unixepoch');
-- datetime to seconds
SELECT strftime('%s', '2024-01-01 00:00:00');
Excel and Google Sheets
- Excel stores dates as days since 1899-12-30. Use:
-- Epoch seconds to Excel date (UTC)
= (A2 / 86400) + DATE(1970,1,1)
-- Format cell as Custom: yyyy-mm-dd"T"hh:MM:ss
= (A2 / 86400) + DATE(1970,1,1)
Adjust for time zones by adding or subtracting hours/24.
Java, C#, and PHP Quick Notes
long sec = 1704067200L;
Instant instant = Instant.ofEpochSecond(sec);
ZonedDateTime zdt = instant.atZone(ZoneId.of('UTC'));
var sec = 1704067200L;
var dt = DateTimeOffset.FromUnixTimeSeconds(sec).UtcDateTime;
$sec = 1704067200;
$dt = (new DateTime('@' . $sec))->setTimezone(new DateTimeZone('UTC'));
Real World Examples
- Logs and monitoring: Convert server logs (Nginx, CloudFront, Kubernetes) timestamps to local time for troubleshooting.
- API payloads: Many APIs send or expect epoch seconds. Example: Stripe, Slack, and JWT use exp as seconds.
- Databases: Use integer epoch fields for faster range filters and partitioning.
- Data pipelines: ETL steps convert mixed date formats into a unified epoch for joins and aggregations.
- Spreadsheets: Analysts often receive CSVs with Unix time and need a quick conversion.
- Scheduling: Compute next run times, TTL, and expiry windows using epoch math.
- Search and SEO: Output ISO 8601 dates in sitemaps and structured data, sourced from epoch fields.
Common Mistakes
- Mixing units: Treating milliseconds like seconds, or vice versa. 1704067200000 is not seconds.
- Ignoring UTC: Converting in local time when the spec expects UTC.
- DST surprises: Formatting local time without a proper time zone database.
- Rounding errors: Using float math instead of integers; not flooring seconds when needed.
- 2038 problem: On old 32-bit systems, times beyond 2038-01-19 overflow.
- Ambiguous strings: Using 01/02/03 without a locale or timezone. Use ISO 8601.
- Timezone abbreviations: EST can be ambiguous. Prefer IANA zones like America/New_York.
- Negative timestamps: Dates before 1970 need library support; not all systems handle them well.
Best Practices
- Store UTC as epoch integers. Document the unit clearly (sec or ms).
- Use ISO 8601 or RFC 3339 for interchange. Include Z or a clear offset.
- Convert to local time only for display. Keep storage and APIs in UTC.
- Validate ranges. Reject impossible values (for example, 20-digit ms where sec is expected).
- Use trusted libraries and standard functions. Skip manual parsing if possible.
- Avoid floats for time arithmetic. Use integers or duration types.
- Test across time zones and around DST transitions.
- For SEO and rich results, follow Schema.org and Google’s structured data rules for date fields.
Expert Tips
- Database performance: Index epoch columns for hot paths; use range partitioning by month.
- ETL safety: Normalize all inputs to UTC epoch at ingest; keep original raw strings for audits.
- Expiry math: Use floor and ceil carefully. For example, floor to seconds for JWT exp.
- Monitoring windows: Precompute start and end epoch values to avoid repeated conversion.
- Cross-language parity: Write unit tests with fixed epoch-date pairs shared by all services.
- Time zones: Prefer IANA names (e.g., Europe/Berlin) over fixed offsets, since offsets shift with DST.
- Leap seconds: Most systems smear or ignore them. Rely on OS and library behavior; do not hand-roll.
Comparison Table
| Method | Best For | Pros | Cons | Example |
|---|
| ZenixTools (online) | Quick checks, non-coders | Fast, no setup, handles units/zones, ISO 8601 | Manual step, offline not available | Paste 1704067200, copy 2024-01-01T00:00:00Z |
| JavaScript | Front-end, Node.js | Built-in Date, wide support | Time zone formatting needs care | new Date(1704067200*1000).toISOString() |
| Python | Data science, back-end | Strong datetime, zoneinfo | Watch units, environment tz | datetime.fromtimestamp(sec, tz=UTC) |
| Bash/CLI | Servers, quick ops | Ubiquitous, scriptable | date flags differ by OS | date -u -d @1704067200 |
| PostgreSQL | Analytics, storage | Powerful time types | Requires DB access | SELECT to_timestamp(1704067200) |
| Excel/Sheets | Analysts | Familiar UI |
Frequently Asked Questions
- What is epoch time in simple terms?
- It is a count of seconds or milliseconds since 1970-01-01T00:00:00Z (UTC).
- How do I know if my timestamp is seconds or milliseconds?
- Count digits. About 10 digits is seconds. About 13 digits is milliseconds.
- Does epoch time include time zones?
- No. Epoch is based on UTC. You apply a timezone when displaying.
- How do I convert epoch to ISO 8601?
- Use ZenixTools, or code like new Date(sec*1000).toISOString() in JavaScript.
- What is the difference between ISO 8601 and RFC 3339?
- RFC 3339 is a stricter profile of ISO 8601 used in many web APIs.
- How do I get the current epoch time?
- JavaScript: Math.floor(Date.now()/1000). Python: int(time.time()). Bash: date +%s.
- Why does my time look wrong by hours?
- Likely a timezone offset or DST issue. Convert in UTC first, then format for local time.
- Can I store timestamps as floats?
- Avoid this. Use integers for seconds or milliseconds to prevent precision loss.
- What about dates before 1970?
- Negative timestamps represent dates before the epoch. Some systems have limited support.
- What is the 2038 problem?
- 32-bit signed seconds overflow in 2038. Modern 64-bit systems and libraries avoid it.
- Should APIs return epoch or ISO 8601?
- Prefer ISO 8601 for clarity. If using epoch, document the unit and timezone (UTC).
- How do I handle milliseconds in SQL?
- Use TIMESTAMP_MILLIS (BigQuery) or multiply/divide by 1000 to align with seconds.
- Why does JavaScript Date use milliseconds?
- JavaScript Date is based on milliseconds since epoch by design. Multiply seconds by 1000.
- Do leap seconds affect epoch time?
- Unix time ignores leap seconds. Most systems smear or adjust; rely on standard libraries.
- What is the safest display format?
- Use ISO 8601 with Z (UTC) or an explicit offset, like 2024-09-04T11:00:00-04:00.
Conclusion
Epoch conversion underpins logs, APIs, analytics, and user-facing dates. When you epoch convert, always check the unit, stick to UTC for storage, and use ISO 8601 for sharing. ZenixTools makes this fast and reliable, while code snippets here cover JavaScript, Python, SQL, CLI, and spreadsheets. Follow the tips and best practices to avoid hard-to-find time bugs.
Call To Action
Try the ZenixTools Epoch Converter now. Paste a timestamp, choose seconds or milliseconds, and get a clean ISO 8601 date in seconds. Need the reverse? Type a date and copy the epoch. Keep this guide handy whenever you need to epoch convert quickly and correctly.
Internal Link Suggestions
- ZenixTools Unix Timestamp Converter
- ZenixTools ISO 8601 Date Formatter
- ZenixTools Time Zone Converter
- ZenixTools Cron to Human Schedule Converter
- ZenixTools Date Difference Calculator
External References
- Google Search Central: Structured data guidelines for dates and times
- MDN Web Docs: Date and time in JavaScript
- W3C: Date and Time Formats
- Schema.org: Date and DateTime types
- MDN Web Docs: Intl.DateTimeFormat