Joda-Time Gets Default Time Zone Names in Java

Tags: Joda Time Joda DateTimeUtils Joda DateTimeZone

In this Joda-Time tutorial, we show you how to use Joda-Time’s DateTimeUtils class to get the list of default time zone names in a Java program.

Add Joda Time library to your Java project

To use Joda Time Java library in the Gradle build project, add the following dependency into the build.gradle file.

compile group: 'joda-time', name: 'joda-time', version: '2.10.9'

To use Joda Time Java library in the Maven build project, add the following dependency into the pom.xml file.

<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>2.10.9</version>
</dependency>

To download the Joda Time .jar file you can visit Joda Time releases page at github.com/JodaOrg/joda-time

Get Default Time Zone Names

In the following Java program, we use DateTimeUtils.getDefaultTimeZoneNames() utility method to get the default map of time zone names.

GetDefaultTimeZoneNames.java

import org.joda.time.DateTimeUtils;
import org.joda.time.DateTimeZone;

import java.util.Map;

public class GetDefaultTimeZoneNames {
    public static void main(String[] args) {

        Map<String, DateTimeZone> map = DateTimeUtils.getDefaultTimeZoneNames();

        for(Map.Entry entry : map.entrySet()) {
            System.out.println(entry.getKey() + " - " + entry.getValue().toString());
        }
    }
}
The output is:
UT - UTC
UTC - UTC
GMT - UTC
EST - America/New_York
EDT - America/New_York
CST - America/Chicago
CDT - America/Chicago
MST - America/Denver
MDT - America/Denver
PST - America/Los_Angeles
PDT - America/Los_Angeles

Happy Coding 😊