ThisCalculator

Everyday

Java Epoch Time Converter: How to Use It

Updated · Standard formula, shown below

The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.

This calculator converts between Unix epoch time (seconds since January 1, 1970 UTC) and human-readable dates, or between a date and its epoch seconds. Enter either a timestamp or a date, and get the corresponding value in the other format, along with the UTC and local time representations. It handles both seconds and milliseconds, which is a common source of confusion.

Formula

The core formula is simple: epoch time = (date – January 1, 1970 00:00:00 UTC) in seconds. For milliseconds, multiply by 1000. Conversely, to get a date from epoch seconds, add that many seconds to the epoch.

  • t – epoch time in seconds (integer, can be negative for dates before 1970).
  • ms – epoch time in milliseconds (often used by JavaScript and Java’s System.currentTimeMillis()).
  • UTC – Coordinated Universal Time, the standard time zone for epoch time.
  • Local time – the date in your system’s time zone, which may differ from UTC.

Worked Example

Using the default value of 1,700,000,000 seconds (which is in the future relative to 2024):

  1. Start with the epoch seconds: 1,700,000,000.
  2. Convert to milliseconds (if needed): 1,700,000,000 × 1000 = 1,700,000,000,000 ms.
  3. Add to the epoch (January 1, 1970 00:00:00 UTC): 1,700,000,000 seconds later is November 14, 2023 22:13:20 UTC.
  4. Your local time will be that instant adjusted for your time zone (e.g., in New York, EST is UTC-5, so it would be 17:13:20).

The calculator’s first output shows the UTC date, and the second shows your local date. For the default input, the UTC date is 2023-11-14 22:13:20.

Why Java Uses Epoch Time

Java’s System.currentTimeMillis() returns the current time as milliseconds since the Unix epoch. The language’s original date classes (java.util.Date and java.util.Calendar) are built around this, storing time internally as a long integer. This makes arithmetic (like adding days) trivial—just add 86,400,000 milliseconds per day. However, it also means you need a converter to read the value in a human-friendly way.

The newer java.time API (introduced in Java 8) uses a different representation, but the epoch second is still a fundamental concept for interop with databases, file systems, and network protocols.

How to Choose Between Seconds and Milliseconds

Most systems use one or the other, and mixing them up is a classic bug. Here’s a quick guide:

  • Unix/POSIX – typically seconds.
  • Java – System.currentTimeMillis() gives milliseconds.
  • JavaScript – Date.now() gives milliseconds.
  • Python – time.time() gives seconds (as a float).
  • Databases – varies by type; MySQL uses seconds for UNIX_TIMESTAMP(), PostgreSQL can store either.

If you see a 13-digit number, it’s almost certainly milliseconds. A 10-digit number is seconds. This converter accepts both, so you can verify which one you have.

Common Problems and Misconceptions

One frequent issue is time zone confusion. Epoch time is always UTC—it does not have a time zone. When you convert to a local date, the result depends on your system’s time zone, but the underlying epoch value is absolute. Another problem is the year 2038 problem: on 32-bit systems, a signed integer can only hold seconds up to January 19, 2038. Java’s long is 64-bit, so it won’t overflow, but older C-based systems might.

Also, be aware that some converters expect milliseconds but you provide seconds, or vice versa. Always check the number of digits. A date like 2020-01-01 has an epoch of 1577836800 (seconds) or 1577836800000 (milliseconds).

Alternatives and Built-in Tools

If you’re writing Java code, you don’t need this calculator—you can use the built-in methods:

  • Instant.now().getEpochSecond() – seconds.
  • Instant.now().toEpochMilli() – milliseconds.
  • Instant.ofEpochSecond(seconds) – convert back to a date.
  • Instant.ofEpochMilli(millis) – convert milliseconds to a date.

For shell scripting, the date command on Linux/macOS can do conversions: date -d @1577836800. Online converters are handy when you’re debugging or reading logs, but knowing the built-in methods saves time.

Safety and Accuracy Notes

This calculator uses the standard formula and does not account for leap seconds (which are occasionally added to UTC). For almost all practical purposes, the difference is negligible. Also, the local time output depends on your device’s time zone setting; if you need a specific time zone, convert manually or use a tool that lets you specify it.

When working with epoch times, always store them in UTC and convert only for display. This avoids daylight saving time errors. For dates before 1970, the epoch value is negative—this calculator accepts negative numbers.

Frequently Asked Questions

What is the current epoch time?

You can get it from this calculator by leaving the default value and seeing the date, but for a live value, use System.currentTimeMillis() in Java or date +%s in Linux. The epoch time increases by one every second.

Why does my epoch time have 13 digits?

That means it’s in milliseconds, not seconds. For example, 1700000000000 milliseconds is 1700000000 seconds. Divide by 1000 to get seconds, or enter it directly into the milliseconds field of this converter.

How do I convert epoch time to a date in Java?

Use Instant.ofEpochSecond(seconds) or Instant.ofEpochMilli(millis), then apply a time zone with atZone(ZoneId.of("UTC")) to get a ZonedDateTime. For example: Instant.ofEpochSecond(1700000000).atZone(ZoneId.of("UTC")).

Is epoch time the same as Unix time?

Yes, they are synonymous. Both refer to the number of seconds since January 1, 1970 00:00:00 UTC, excluding leap seconds. Some systems call it POSIX time or Unix timestamp.

Can epoch time be negative?

Yes, for dates before 1970. For example, January 1, 1960 is -315619200 seconds. This calculator accepts negative values, so you can convert historical dates.

What happens in the year 2038?

On 32-bit systems using a signed 32-bit integer, the epoch will overflow at 03:14:07 UTC on January 19, 2038. Java’s long is 64-bit, so it won’t be affected. Most modern systems use 64-bit integers, so the issue is largely theoretical today.

Related

Formula used
in t | Epoch seconds | s | 1700000000 | 0
in ms | Epoch milliseconds | ms | 0 | 0
out dt | Date (UTC) | - | if(ms>0, ms, t*1000) | time
out local | Date (local) | - | if(ms>0, ms, t*1000) | time

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.