TimeZone ID and display name
In this chapter you will learn:
Get TimeZone ID
String getID()
Gets the ID of this time zone.
import java.util.TimeZone;
// ja va 2s . 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 availablve 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 a va 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:
Etc/GMT+12/*from j a v a 2 s .co m*/
Etc/GMT+11
MIT
Pacific/Apia
Pacific/Midway
Pacific/Niue
...
...
Pacific/Enderbury
Pacific/Tongatapu
Etc/GMT-14
Pacific/Kiritimati
Get display name for a timezone
String getDisplayName()
returns a time zone name in the default locale.
import java.util.TimeZone;
/*from ja v a 2s. co m*/
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:
Home » Java Tutorial » Date, Time