timestamper.online
Back to Guides

How to Handle Unix Timestamps in Java

Working with Epoch time in Java using `java.time.Instant` (Modern Java 8+).

1. Get Current Timestamp
java
import java.time.Instant;

// Get current timestamp (seconds)
long now = Instant.now().getEpochSecond();
2. Convert Date to Timestamp
java
import java.time.Instant;

// Parse ISO string to timestamp
long ts = Instant.parse("2024-01-01T00:00:00Z").getEpochSecond();
3. Convert Timestamp to Readable Date
java
import java.time.Instant;

// Timestamp to ISO String
String date = Instant.ofEpochSecond(1704067200L).toString();

Need to convert a specific timestamp right now?

Use Online Converter