TimeZone ID and display name

In this chapter you will learn:

  1. How to get TimeZone ID
  2. Get available timezone ids
  3. Get display name for a timezone

Get TimeZone ID

String getID() Gets the ID of this time zone.
import java.util.TimeZone;
/*  ja  v  a 2 s . c om*/
public class Main {

  public static void main(String[] args) {
    TimeZone tz = TimeZone.getTimeZone("America/New_York");

    System.out.println(tz.getID());
  }
}

The output:

Get available timezone ids

The following two methods return available timezone ids.

  • static String[] getAvailableIDs()
    Gets all the available IDs supported.
  • static String[] getAvailableIDs(int rawOffset)
    Gets the available IDs according to the given time zone offset in milliseconds.
import java.util.TimeZone;
/*from  j  ava  2s . c  om*/
public class Main {

  public static void main(String[] args) {
   String[] ids = TimeZone.getAvailableIDs();
   for(String id: ids){
     System.out.println(id);
   }

  }
}

The output:

Get display name for a timezone

String getDisplayName() returns a time zone name in the default locale.

import java.util.TimeZone;
/*from j a  va 2  s .  c  om*/
public class Main {

  public static void main(String[] args) {
    TimeZone tz = TimeZone.getTimeZone("America/New_York");

    System.out.println(tz.getDisplayName());
  }
}

The output:

Next chapter...

What you will learn in the next chapter:

  1. Get daylight saving
Home » Java Tutorial » Date, Time, Calendar, TimeZone

Date

    Date class
    Date comparison
    Converting date value
    DateFormat class
    Format time
    DateFormat and Locale
    Convert String to Date

Calendar

    Calendar class
    Calendar date time getter
    Calendar set hour,minute,second
    Calendar calculation
    Calendar comparison
    Calendar properties
    GregorianCalendar

TimeZone

    TimeZone
    TimeZone ID and display name
    TimeZone daylight saving

DateFormat

    DateFormat class
    Format time
    DateFormat and Locale
    Convert String to Date
    SimpleDateFormat
    Parse date string into Date object
    SimpleDateFormat day format
    SimpleDateFormat Hour Time format
    SimpleDateFormat format minute
    SimpleDateFormat to format month
    SimpleDateFormat to format second value
    SimpleDateFormat to format TimeZone
    SimpleDateFormat to format year
    SimpleDateFormat to combine formatting flags