CURRENT EPOCH · EPOCHTIME.TOOLS · A PRECISION INSTRUMENT FOR TIME
Converter Batch Difference Blog
Languages
JavaScript Python TypeScript Go Rust Java PHP SQL Bash
Specialty
LDAP Timestamp .NET Ticks Chrome/WebKit Cocoa / Core Data Discord Timestamp Excel OADate Unix Hex
Standards
ISO 8601 Guide Year 2038 NTP Timestamp GPS Time Julian Day

Get current Unix timestamp

Use `Instant.now()`. It represents a point on the timeline, independent of timezone.

Seconds

import java.time.Instant;

long secs = Instant.now().getEpochSecond();
// → 1735689600

Milliseconds

long ms = Instant.now().toEpochMilli();
// → 1735689600000
// or the older:
System.currentTimeMillis();

Microseconds and nanoseconds

Instant now = Instant.now();
long micros = now.getEpochSecond() * 1_000_000L + now.getNano() / 1000;
long nanos = now.getEpochSecond() * 1_000_000_000L + now.getNano();

Convert epoch to Instant / ZonedDateTime

Build an Instant from epoch, then convert to a ZonedDateTime when you need a timezone.

Seconds → Instant

Instant inst = Instant.ofEpochSecond(1735689600);
System.out.println(inst);
// → 2025-01-01T00:00:00Z

Milliseconds → Instant

Instant inst = Instant.ofEpochMilli(1735689600000L);

In a specific timezone

import java.time.ZonedDateTime;
import java.time.ZoneId;

ZonedDateTime zdt = Instant.ofEpochSecond(1735689600)
    .atZone(ZoneId.of("America/New_York"));
System.out.println(zdt);
// → 2024-12-31T19:00-05:00[America/New_York]

Convert to epoch

Any Instant has `.getEpochSecond()` and `.toEpochMilli()`.

From a ZonedDateTime

ZonedDateTime zdt = ZonedDateTime.now();
long secs = zdt.toEpochSecond();
long ms = zdt.toInstant().toEpochMilli();

From components

import java.time.LocalDateTime;
import java.time.ZoneOffset;

long secs = LocalDateTime.of(2025, 1, 1, 0, 0, 0)
    .toEpochSecond(ZoneOffset.UTC);
// → 1735689600

Format for display

Use `DateTimeFormatter` — Java's built-in formatter.

ISO 8601

import java.time.format.DateTimeFormatter;

String iso = ZonedDateTime.now().format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
// → "2025-01-01T12:34:56.789-05:00"

Custom format

DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
String s = ZonedDateTime.now().format(fmt);

Parse common formats

`Instant.parse()` handles ISO 8601 directly. For other formats, use `DateTimeFormatter`.

ISO 8601

Instant inst = Instant.parse("2025-01-01T00:00:00Z");
long secs = inst.getEpochSecond();

Custom format

DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime ldt = LocalDateTime.parse("2025-01-01 12:00:00", fmt);
long secs = ldt.toEpochSecond(ZoneOffset.UTC);

Common gotchas

Java date pitfalls.

Don't use java.util.Date

// Old Date is mutable, timezone-broken, deprecated for new code.
// Use Instant, LocalDateTime, ZonedDateTime instead.

LocalDateTime has NO timezone

// LocalDateTime.now() returns the local clock reading
// but has no tzinfo — you can't convert it to epoch
// without specifying a ZoneId.
LocalDateTime ldt = LocalDateTime.now();
// ldt.toEpochSecond(ZoneOffset.UTC) — explicit zone required

Instant.now() is UTC, period

// Don't worry about your machine's timezone for Instant.
// It always represents a UTC point on the timeline.

Use the converter

Need to quickly check what a specific timestamp converts to? Use the main converter — paste any value and get every format back.

Working with many timestamps at once? Try the batch converter — paste a list, get a CSV or JSON file back.