How to get TimeZone from android mobile?
Have you tried to use TimeZone.getDefault()
:
Most applications will use TimeZone.getDefault() which returns a TimeZone based
on the time zone where the program is running.
Ref: http://developer.android.com/reference/java/util/TimeZone.html
How to get timezone on Android device?
Android Developer reference: https://developer.android.com/reference/java/util/TimeZone.html
If you want to get TimeZone-TZ, use TimeZone.getID()
.
TimeZone timeZone = TimeZone.getDefault();
String name = timeZone.getID(); // "Asia/Seoul"
Getting the current time zone in android application
Use this
Calendar cal = Calendar.getInstance();
TimeZone tz = cal.getTimeZone();
Log.d("Time zone","="+tz.getDisplayName());
or you can also use the java.util.TimeZone
class
TimeZone.getDefault().getDisplayName()
How to get the timezone offset in GMT(Like GMT+7:00) from android device?
This code return me GMT offset.
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"),
Locale.getDefault());
Date currentLocalTime = calendar.getTime();
DateFormat date = new SimpleDateFormat("Z");
String localTime = date.format(currentLocalTime);
It returns the time zone offset like this: +0530
If we use SimpleDateFormat below
DateFormat date = new SimpleDateFormat("z",Locale.getDefault());
String localTime = date.format(currentLocalTime);
It returns the time zone offset like this: GMT+05:30
How to get the abbreviation / Country code of mobile timezone in android?
About terminology:
We call strings like "America/Denver" etc. (in format region/city) timezone identifiers, not names. These ids are defined in IANA-TZDB. Timezone names and abbreviations are a totally different concept. Those data usually have their origins in CLDR-files (from Unicode consortium, for example here) and correspond to what most people expect IN THEIR LOCALES. These names are highly localized. In general, there is no international standard, neither for identifiers nor for names. Latter ones are just following local customs.
Mapping:
A mapping from timezone identifiers to country codes and vice versa can be found in IANA-TZDB. You can then quickly see that there is no unique mapping as you expect. Examples:
Europe/Zurich can be valid in Switzerland, Germany(sic!) and
Liechtenstein.
Or trivially:
US has more than one timezone (America/New_York, America/Chicago,
etc.)
Your hope to get unique timezone abbreviations using the expression
Calendar.getInstance().getTimeZone().getDisplayName(false, TimeZone.SHORT);
is not realistic. The method to get tz abbreviations you describe is correct. However, as you yourself have noticed in your other SO-post the results differ from one Android device to another. The main reason is that different devices (dalvik vms) often have different data for timezone names (and the OpenJDK-Oracle-VMs, too).
A unique mapping from timezone names and abbreviations to country codes is usually not possible. Counter examples: "IST" can stand for "India Standard Time" or for Israel time zone. Or: "BST" is used in "Europe/London" (during summer time) or in "Pacific/Bougainville" (all the year).
About daylight saving:
Identifiers are NOT sensitive for daylight saving. The related data can be daylight saving or not, dependent on the associated time. Timezone names and abbreviations are often (not always) sensitive, compare for example "PST" or "PDT" in US.
Summary and advice:
Do not use timezone names or abbreviations for anything other than display purposes. You should not use these localized data for any conclusions or storage purposes.
Related Topics
The Type Java.Lang.Charsequence Cannot Be Resolved in Package Declaration
Getresourceasstream() Is Always Returning Null
Listening for Input Without Focus in Java
Printing a Jframe and Its Components
What Is the Use of System.In.Read()
Read the Output from Java Exec
Displaying a Histogram of Image Data
Getting Strange Output When Printing Result of a String Comparison
Jpanel & Components Change Position Automatically
How to Call Launch() More Than Once in Java
Java.Sql.Sqlexception: Column Count Doesn't Match Value Count at Row 1
Java.Lang.Illegalstateexception: Scanner Closed
Differencebetween Unidirectional and Bidirectional JPA and Hibernate Associations