How to Get the Current Time in Java with Instant.now
Instant.now() captures the current moment as a point on the UTC timeline, with no time zone involved. That makes it the right type for timestamps you store, compare or send to other systems.
Syntax
import java.time.Instant;
Instant <now> = Instant.now();
| Part | What it does |
|---|---|
Instant | A single moment on the timeline, in UTC. |
Instant.now() | Reads the current moment from the system clock. |
<now> | The moment; printing it gives an ISO 8601 text ending in Z, for UTC. |
The JDK 25 documentation for Instant.now: "Obtains the current instant from the system clock. This will query the system UTC clock to obtain the current instant."
The Example
The example prints the current instant, then runs again with the computer's time zone set to New York, to show the result stays in UTC.
Prerequisites
- A JDK, the Java Development Kit.
java Main.javaruns a single file without compiling it first. This guide uses OpenJDK 25.0.5.1.
Step 1: Write the Code
Create a file named Main.java:

import java.time.Instant;
public class Main {
public static void main(String[] args) {
Instant now = Instant.now();
System.out.println(now);
}
}
Step 2: Run It in Two Time Zones
The second command sets the TZ variable, which tells programs on macOS and Linux which time zone to use, for that one run:
java Main.java
TZ=America/New_York java Main.java
2026-11-26T06:34:09.969248Z
2026-11-26T06:34:10.650024Z

Both runs printed UTC time, a second apart; New York's time zone didn't change the value. Your times will differ. The TZ=... prefix works in zsh and bash; in PowerShell, run java Main.java on its own.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Expecting Instant to show local time | It always prints UTC, with a Z | Convert it with atZone(ZoneId.systemDefault()) for display |
Using LocalDateTime.now() for timestamps | The value has no time zone, so other systems can't tell when it happened | Use Instant.now() |
Comparing instants with == | Compares objects, not moments | Use isBefore, isAfter or equals |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The printed hour differs from your clock | Instant prints UTC | Add your offset, or convert with atZone |
cannot find symbol for Instant | The import is missing | Add import java.time.Instant; |
FAQ
How precise is Instant.now()?
It can hold nanoseconds; on this computer it printed six digits after the seconds, microseconds.
How do I get Unix seconds from it?
now.getEpochSecond() returns the seconds since 1970-01-01T00:00:00Z.
Conclusion
Instant.now() returns the current moment in UTC, the same on every computer whatever its time zone. Store and compare Instants, and convert to a time zone only when showing them to people.
Additional Resources
- Instant, in the JDK 25 API documentation.
