🌐
Jenkov
jenkov.com › tutorials › java-date-time › java-util-timezone.html
Java's java.util.TimeZone
June 23, 2014 - But you only need to use the ZoneId class if you are using the Java 8 date time classes (like the ZonedDateTime class). If you use a Calendar (from the Java 7 and earlier date time API) you can still use the java.util.TimeZone class. Here is a simple example of how you can get the TimeZone from a Calendar:
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › TimeZone.html
TimeZone (Java Platform SE 8 )
2 weeks ago - The syntax of a custom time zone ... must be between 0 to 23 and Minutes must be between 00 to 59. For example, "GMT+10" and "GMT+0010" mean ten hours and ten minutes ahead of GMT, respectively....
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › util › TimeZone.html
TimeZone (Java Platform SE 7 )
The syntax of a custom time zone ... must be between 0 to 23 and Minutes must be between 00 to 59. For example, "GMT+10" and "GMT+0010" mean ten hours and ten minutes ahead of GMT, respectively....
🌐
Microsoft Learn
learn.microsoft.com › en-us › java › openjdk › timezones
Configure timezones in Java | Microsoft Learn
January 8, 2025 - The following example configures the container to use the America/New_York timezone by setting the TZ environment variable and installing the tzdata package: # Use a base image with Java installed FROM mcr.microsoft.com/openjdk/jdk:21-mariner ...
🌐
Dariawan
dariawan.com › tutorials › java › java-timezone-examples
Java TimeZone Examples | Dariawan
August 17, 2019 - We can use Calendar's setTimeZone() to convert between TimeZone ... import java.util.Calendar; import java.util.TimeZone; public class TimeZoneConvertExample { static void printCalendarTimeZone(Calendar calendar) { TimeZone tz = calendar.getTimeZone(); System.out.printf("Time In Millis: %s\n", calendar.getTimeInMillis()); System.out.printf("Hour : %s\n", calendar.get(Calendar.HOUR_OF_DAY)); System.out.printf("Time Zone ID : %s\n", tz.getID()); System.out.printf("Time Zone Name: %s\n", tz.getDisplayName()); System.out.println(); } public static void main(String[] args) { TimeZone tz1 = TimeZone.getTimeZone("Asia/Jakarta"); TimeZone tz2 = TimeZone.getTimeZone("Asia/Tokyo"); Calendar cal = Calendar.getInstance(tz1); printCalendarTimeZone(cal); cal.setTimeZone(tz2); printCalendarTimeZone(cal); } }
🌐
Baeldung
baeldung.com › home › java › java dates › set the time zone of a date in java
Set the Time Zone of a Date in Java | Baeldung
September 8, 2024 - Date nowUtc = new Date(); TimeZone asiaSingapore = TimeZone.getTimeZone(timeZone); In Java 7, we need to use the Calendar class to represent a date with a time zone.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › util › TimeZone.html
TimeZone (Java SE 17 & JDK 17)
January 20, 2026 - The syntax of a custom time zone ... must be between 0 to 23 and Minutes must be between 00 to 59. For example, "GMT+10" and "GMT+0010" mean ten hours and ten minutes ahead of GMT, respectively....
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › util › TimeZone.html
TimeZone (Java SE 11 & JDK 11 )
January 20, 2026 - NormalizedCustomID: GMT Sign TwoDigitHours : Minutes Sign: one of + - TwoDigitHours: Digit Digit Minutes: Digit Digit Digit: one of 0 1 2 3 4 5 6 7 8 9 For example, TimeZone.getTimeZone("GMT-8").getID() returns "GMT-08:00". For compatibility with JDK 1.1.x, some other three-letter time zone ...
🌐
Oracle
docs.oracle.com › javase › 6 › docs › api › java › util › TimeZone.html
TimeZone (Java Platform SE 6)
... Gets the available IDs according to the given time zone offset in milliseconds. ... an array of IDs, where the time zone for that ID has the specified GMT offset. For example, "America/Phoenix" and "America/Denver" both have GMT-07:00, but differ in daylight savings behavior.
🌐
Bureau of Economic Geology
beg.utexas.edu › lmod › agi.servlet › doc › detail › java › util › TimeZone.html
java.util Class TimeZone
... Gets the available IDs according to the given time zone offset. ... an array of IDs, where the time zone for that ID has the specified GMT offset. For example, "America/Phoenix" and "America/Denver" both have GMT-07:00, but differ in daylight savings behavior.
Find elsewhere
Top answer
1 of 1
3

Avoid legacy classes

You are using terrible date-time classes that were supplanted years ago by the modern java.time classes defined in JSR 310.

Keep servers in UTC

The default time zone (and locale) of your server should not impact your code. The settings there are out of your control as a programmer. So rather than rely on those defaults, always specify the desired/expected time zone (and locale) by passing optional argument to various methods.

Tip: Best practice is to generally keep your servers in UTC as their default time zone. Indeed, most of your business logic, logging, data exchange, and data storage should be done in UTC.

java.time

LocalTime

Each location has a target time-of-day.

LocalTime targetTimeOfDayParis = LocalTime.of( 9 , 0 ) ;  // 09:00.
LocalTime targetTimeOfDayNewYork = LocalTime.of( 9 , 0 ) ;  // 09:00.

Instant.now

Get the current moment in UTC.

Instant now = Instant.now() ;  // No need for time zone here. `Instant` is always in UTC, by definition.

ZoneId

When is that moment today? First define our time zones.

ZoneId zParis = ZoneId.of( "Europe/Paris" ) ;
ZoneId zNewYork = ZoneId.of( "America/New_York" ) ;

Instant::atZone

Then adjust from UTC in the Instant to the very same moment as seen through the wall-clock time employed by the people of a particular region (a time zone). That adjusted moment is represented by the ZonedDateTime class.

Note that this is not changing the moment. We have the same point on the timeline on both. Only the wall-clock time is different. Like two people on long-distance phone call can simultaneously look up at the clock on their respective wall and see a different time-of-day (and date!) at the very same moment.

ZonedDateTime zdtParis = now.atZone( zParis ) ;
ZonedDateTime zdtNewYork = now.atZone( zNewYork ) ;

ZonedDateTime::with

Change the time-of-day to our target. The ZonedDateTime::with method will generate a new ZonedDateTime object with values based on the original excepting for the values you pass. Here we pass a LocalTime to change from the hour & minute & second & fractional-second of the original.

The is the key part where we diverge for Paris versus New York. Nine in the morning in Paris is a very different moment than 9 AM in New York, several hours apart.

ZonedDateTime zdtParisTarget = zdtParis.with( targetTimeOfDayParis ) ;
ZonedDateTime zdtNewYorkTarget = zdtNewYork.with( targetTimeOfDayNewYork ) ;

Compare with isBefore

Did we miss 9 AM in either zone yet?

boolean pastParis = zdtParisTarget.isBefore( zdtParis ) ;
boolean pastNewYork = zdtNewYorkTarget.isBefore( zdtNewYork ) ;

If past, then add a day.

if( pastParis ) {
    zdtParisTarget = zdtParisTarget.plusDays( 1 ) ;
}

if( pastNewYork ) {
    zdtNewYorkTarget = zdtNewYorkTarget.plusDays( 1 ) ;
}

Duration

Calculate elapsed time using Duration class.

Duration durationParis = Duration.between( now , zdtParisTarget.toInstant() ) ;
Duration durationNewYork = Duration.between( now , zdtNewYorkTarget.toInstant() ) ;

Sanity-check that the durations are in the future, not the past.

if( durationParis.isNegative() ) { … handle error … } 
if( durationNewYork.isNegative() ) { … handle error … } 

Ditto for zero.

if( durationParis.isZero() ) { … handle error … } 
if( durationNewYork.isZero() ) { … handle error … } 

In real work, I would check to see if the duration is extremely tiny. If so brief that the code below may take longer than span of time, add some arbitrary amount of time. I'll leave that as an exercise for the reader.

Schedule work to be done

Prepare the work to be done.

Runnable runnableParis = () -> taskParis.work() ;
Runnable runnableNewYork = () -> taskNewYork.work() ;

Or you could write a utility that takes an ZoneId argument, looks up the work to be done, and returns a Runnable.

Schedule the work to be done. See the Oracle Tutorial on the Executor framework. This framework greatly simplifies scheduling work to be done on a background thread.

We schedule a task to be run after a certain number of minutes, seconds, or any such granularity has elapsed. We specify a number and a granularity with the TimeUnit enum. We can extract the number from our Duration calculated above.

ScheduledExecutorService scheduler = Executors.newScheduledThreadPool( 1 );

ScheduledFuture<?> futureParis = scheduler.schedule( runnableParis , durationParis.toSeconds() , TimeUnit.SECONDS ) ;
ScheduledFuture<?> futureNewYork = scheduler.schedule( runnableNewYork , durationNewYork.toSeconds() , TimeUnit.SECONDS ) ;

The future object lets you check on progress status. You may not need it at all.

IMPORTANT: Be sure to gracefully shutdown your ScheduledExecutorService when no longer needed, such as when your app is ending.

Caveat: I have not tried any of this code. But it should get you headed into the right direction.

Note the repetition. There is no need to hard-code the city name in all those variables. You could write this logic once in a method that takes the ZoneId as an argument, and the time-of-day too if there is any chance it would vary by city. Then call that method for any number of zones.

List< ZoneId > zones = 
    List.of( 
            ZoneId.of( "Europe/Paris" ) , 
            ZoneId.of( "America/New_York" ) , 
            ZoneId.of( "Asia/Kolkata" ) 
    ) 
;
for( ZoneId z : zones ) {
    workManager.scheduleForZone( z ) ;
}
🌐
Oracle
docs.oracle.com › javase › tutorial › datetime › iso › timezones.html
Time Zone and Offset Classes (The Java™ Tutorials > Date Time > Standard Calendar)
July 21, 2013 - For example, the offset for Tokyo is +09:00. The Date-Time API provides two classes for specifying a time zone or an offset: ZoneId specifies a time zone identifier and provides rules for converting between an Instant and a LocalDateTime. ZoneOffset specifies a time zone offset from Greenwich/UTC ...
🌐
Oracle
docs.oracle.com › en › java › javase › 25 › docs › api › java.base › java › util › TimeZone.html
TimeZone (Java SE 25 & JDK 25)
January 20, 2026 - For example, "America/Phoenix" and "America/Denver" both have GMT-07:00, but differ in daylight saving behavior. ... Returns a stream of the available IDs supported. ... Unlike getAvailableIDs(), this method does not create a copy of the TimeZone IDs array. ... Gets the default TimeZone of ...
🌐
javaspring
javaspring.net › blog › java-timezone-list
Java Timezone List: A Comprehensive Guide — javaspring.net
In this example, we create a ZoneId object representing the "America/New_York" time zone and print it to the console. Once you have a ZoneId object, you can use it to convert a LocalDateTime object to a ZonedDateTime object.
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › util › TimeZone.html
TimeZone (Java SE 21 & JDK 21)
January 20, 2026 - The syntax of a custom time zone ... be between 0 to 23 and Minutes/Seconds must be between 00 to 59. For example, "GMT+10" and "GMT+0010" mean ten hours and ten minutes ahead of GMT, respectively....
🌐
Atlassian Support
support.atlassian.com › atlassian-knowledge-base › kb › how-to-set-the-timezone-for-the-java-environment
How to set the timezone for the Java environment | Atlassian knowledge base | Atlassian Support
April 17, 2025 - The timezone can be edited by changing the server clock on the server that is running JAVA or changing the properties as explained below. The value of the timezone can be altered with the below JVM argument, which is set as per our Setting Properties and Options on Startup documentation. The example below shows how to set it for America/Chicago:
🌐
Medium
medium.com › @davoud.badamchi › tackling-timezones-in-java-a-comprehensive-guide-for-developers-5bad69b2c079
Tackling Timezones in Java: A Comprehensive Guide for Developers | by Davoud Badamchi | Medium
July 3, 2024 - Practical Examples and Challenges: We provided examples of handling different timezones in global applications, including real-world scenarios in Australia, Samoa, and the West Bank. Timezones in Java and Spring Boot: We covered the java.time package in depth, highlighting classes like LocalDate, LocalTime, LocalDateTime, ZonedDateTime, OffsetDateTime, and ZoneId, with practical examples and benefits of each class.
🌐
Baeldung
baeldung.com › home › java › java dates › display all time zones with gmt and utc in java
Display All Time Zones With GMT and UTC in Java | Baeldung
March 17, 2024 - Here’s a snippet of how the output will look like: Time zones in UTC: (UTC+14:00) Pacific/Apia (UTC+14:00) Pacific/Kiritimati (UTC+14:00) Pacific/Tongatapu (UTC+14:00) Etc/GMT-14 · Java 8 makes this task easier by using the Stream and Date ...
🌐
DEV Community
dev.to › sadiul_hakim › time-zones-and-offsets-in-java-2d8m
Time Zones and Offsets in Java - DEV Community
September 19, 2025 - import java.time.ZonedDateTime; ... System.out.println("New York Time: " + newYorkTime); // Example output: 2025-09-19T10:00-04:00[America/New_York] // Convert the New York time to London's time zone ZoneId londonZone = ...
🌐
Oracle
docs.oracle.com › en › java › javase › 22 › docs › api › java.base › java › util › TimeZone.html
TimeZone (Java SE 22 & JDK 22)
July 16, 2024 - The syntax of a custom time zone ... be between 0 to 23 and Minutes/Seconds must be between 00 to 59. For example, "GMT+10" and "GMT+0010" mean ten hours and ten minutes ahead of GMT, respectively....