Java 8

How to Get Current UTC Time in Java (Java 8 to Java 21)

Updated October 2026. Tested on Java 21. Everything below works on Java 8 and later.

The easiest way to get the current UTC time in Java is Instant.now(). It returns a point on the timeline that is always in UTC, no matter which time zone your computer is set to.

This post shows that method and a few others, explains when to use each, and points out a bug in the old SimpleDateFormat approach that many older tutorials still repeat, including the first version of this one.

Quick answer

Instant now = Instant.now();
System.out.println(now);

Output:

2026-10-23T14:52:18.137408810Z

The Z at the end means UTC (“Zulu time”). That is all you need for most cases. Read on if you need a formatted string, a specific type, or testable code.

Get the current UTC time in Java with Instant

Instant represents one moment on the timeline, counted from the epoch (1 January 1970, 00:00 UTC). It has no time zone of its own, and printing it always shows UTC.

Instant instant = Instant.now();
System.out.println("Instant          : " + instant);

Use Instant for timestamps you store, compare or send between systems. It is the simplest and the safest choice.

One detail: the precision depends on your Java version and operating system. Java 8 gives milliseconds. Java 9 and later usually give microseconds, and sometimes more, as in the output above.

Get UTC time with OffsetDateTime or ZonedDateTime

If you want a date-time object that carries the UTC offset, ask for it with ZoneOffset.UTC:

OffsetDateTime offsetNow = OffsetDateTime.now(ZoneOffset.UTC);
ZonedDateTime zonedNow = ZonedDateTime.now(ZoneOffset.UTC);

System.out.println("OffsetDateTime   : " + offsetNow);
System.out.println("ZonedDateTime    : " + zonedNow);

Output:

OffsetDateTime   : 2026-10-23T14:52:18.139754787Z
ZonedDateTime    : 2026-10-23T14:52:18.140338484Z

Use OffsetDateTime when you save a date-time with its offset, for example in a database column or a JSON API. Use ZonedDateTime when you also need time zone rules, such as daylight saving.

Get UTC date and time as LocalDateTime

LocalDateTime localUtc = LocalDateTime.now(ZoneOffset.UTC);
System.out.println("LocalDateTime    : " + localUtc);

Output:

LocalDateTime    : 2026-10-23T14:52:18.140473786

The values are in UTC, but the object does not remember that. Nothing in the output says UTC, and nothing stops another developer from treating it as local time later. Prefer Instant or OffsetDateTime unless you have a good reason.

Format the current UTC time as a String

Build a formatter with the UTC zone, then format an Instant:

DateTimeFormatter formatter =
        DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss 'UTC'").withZone(ZoneOffset.UTC);

System.out.println(formatter.format(Instant.now()));

Output:

2026-10-23 14:52:18 UTC

The withZone(ZoneOffset.UTC) call is what keeps the output in UTC. Without it, formatting an Instant with a pattern throws UnsupportedTemporalTypeException: Unsupported field: YearOfEra, because an Instant has no zone to read the date fields from.

Get UTC time as epoch milliseconds

long millis = Instant.now().toEpochMilli();
System.out.println(millis);

Output:

1792767138140

Epoch milliseconds are always counted from UTC, so this number is the same on every machine at the same moment.

Convert UTC time to another time zone

Keep the instant in UTC and convert only when you show it to a person:

Instant instant = Instant.now();
System.out.println(instant.atZone(ZoneId.of("Asia/Kolkata")));

Output:

2026-10-23T20:22:18.137408810+05:30[Asia/Kolkata]

Same moment, shown as 20:22 in India instead of 14:52 UTC.

Use a Clock to make UTC time testable

Calling Instant.now() directly makes code hard to test, because the time keeps changing. Pass in a Clock instead:

Clock fixed = Clock.fixed(Instant.parse("2026-10-23T10:15:30Z"), ZoneOffset.UTC);
System.out.println(Instant.now(fixed));              // always the same
System.out.println(Instant.now(Clock.systemUTC()));  // the real time

Output:

2026-10-23T10:15:30Z
2026-10-23T14:52:18.152696189Z

In production, use Clock.systemUTC(). In unit tests, use a fixed clock and the result is the same on every run.

The old SimpleDateFormat way is wrong

The first version of this post used SimpleDateFormat to get UTC time. It looks reasonable, but the result is misleading. Here is the old code, run on a machine in India (UTC+5:30):

WRONG

private static Date oldWayWrong() throws Exception {
    SimpleDateFormat utcFormat = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
    utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    SimpleDateFormat localFormat = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
    return localFormat.parse(utcFormat.format(new Date()));
}

Output:

Old method       : Fri Oct 23 14:52:18 IST 2026
Correct instant  : 2026-10-23T14:52:18.199102387Z

Look at the first line. It says IST, but the clock time 14:52 is the UTC time. The real time in India at that moment was 20:22. The method formats the time in UTC, then parses that text as if it were local time, so the number is right but the label is wrong. Anyone who uses the returned Date will be 5 hours and 30 minutes off.

The root cause is that java.util.Date has no time zone. It is just a moment in time, and it always prints in the JVM’s default zone. You cannot “make a Date be UTC”.

RIGHT

Instant now = Instant.now();

If you need a string, format the Instant with a UTC formatter, as shown above.

What about Joda-Time?

Older tutorials, including the first version of this post, suggest the Joda-Time library. You no longer need it. Joda-Time is in maintenance mode, and its own documentation asks Java 8 and later users to move to java.time. Everything Joda did for UTC time is covered by the classes above, with no extra dependency.

Common mistakes

  • Using new Date() and expecting UTC. It holds the correct moment, but prints in the default time zone. Use Instant.
  • Using LocalDateTime.now() for a timestamp. It returns local time with no zone. LocalDateTime.now(ZoneOffset.UTC) gives UTC values, but they carry no zone information.
  • Formatting an Instant without a zone. The formatter throws an exception. Add .withZone(ZoneOffset.UTC).
  • Converting to local time too early. Store and compare in UTC, and convert to the user’s zone only when displaying.
  • Calling now() all over the code. Pass a Clock so tests can control the time.

Which one should you use?

You need Use
A timestamp to store, compare or send Instant.now()
A date-time with its UTC offset, for a database or API OffsetDateTime.now(ZoneOffset.UTC)
UTC time with time zone rules ZonedDateTime.now(ZoneOffset.UTC)
A readable string DateTimeFormatter with .withZone(ZoneOffset.UTC)
A number to store or compare Instant.now().toEpochMilli()
Time you can control in tests Clock.systemUTC() and Clock.fixed(...)

Summary

Instant.now() is the current UTC time in Java, and it works the same on every machine. Use OffsetDateTime when you need the offset, a formatter with withZone(ZoneOffset.UTC) for text, and a Clock for code you want to test. Skip the old SimpleDateFormat trick and Joda-Time.

References

Related posts

Found a mistake or something out of date? Tell us →

Written by

chandrashekhar

Founder of onlinetutorialspoint.com. Enterprise architect with 15+ years in healthcare technology, designing and running systems on AWS and Azure. Writes about building real things with AI, local AI hardware and cloud certifications.

Keep reading

Ask a question or leave a comment