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 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:
Home » Java Tutorial » Date, Time, Calendar, TimeZone