I would like to show the "name" of timezone in my android program. Say if it is "GMT+8:00", then show "HongKong"; By searching, i find that the getDisplayName function should sever my purpose.
http://developer.android.com/reference/java/util/TimeZone.html#getDisplayName(boolean, int, java.util.Locale)
However, in my own program, this function only shows "GMT+8:00" but when i use "getDisplayName" in the Google Open Source Project, it would show the name "HongKong" instead.
Does anyone know the reason behind this?
The getDefault() method of TimeZone class in Java is used to know the default TimeZone for this system or host. This may vary in according to the implementation in different environment. Syntax: public static TimeZone getDefault() Parameters: The method does not take any parameters.
Try this
TimeZone tz = TimeZone.getDefault();
System.out.println(tz.getID());
getDisplayName
returns timezone and getId
returns timezone location name.
You can find out your current time zone by below code
private String getTimeZone() {
Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
TimeZone zone = calendar.getTimeZone();
return zone.getID();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With