I want to get the time zone from the Android mobile when clicking a button.
-
12TimeZone tz = TimeZone.getDefault(); String gmt1=TimeZone.getTimeZone(tz.getID()).getDisplayName(false,TimeZone.SHORT); String gmt2=TimeZone.getTimeZone(tz.getID()).getDisplayName(false,TimeZone.LONG); Log.d("Tag","TimeZone : "+gmt1+"\t"+gmt2); And this is the code – asha v Oct 07 '11 at 09:45
-
10I wouldn't be so rough on asha v. I was just looking for the same thing and the answers I found were different than these ones. Actually searching by the exact "TimeZone.getDefault" led me here. – Yar May 29 '12 at 14:27
13 Answers
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

- 45,245
- 23
- 243
- 245

- 9,170
- 3
- 24
- 30
-
23If you're using **JodaTime**, you can get a DateTimeZone with the following: `DateTimeZone.forTimeZone(TimeZone.getDefault());` – Joshua Pinter Jan 28 '14 at 19:22
-
@JoshPinter which package do I use, the one on android.icu.utils or the java.util? – Neon Warge Sep 03 '16 at 10:03
-
1I changed the time zone from the device to CST, it is not giving me CST back. Is there a way to get the time zone, of the device? – Abhinav Saxena Feb 08 '17 at 05:54
-
I'm wondering, does TimeZone.getDefault get effected if we somehow fake the device's timezone. It seems to be not on the android simulator. – Harvey Jun 18 '20 at 09:12
-
@NeonWarge Both will work, although android.icu only works for API 24 and above. – Nicolas Jul 28 '20 at 18:45
-
TimeZone tz = TimeZone.getDefault();
System.out.println("TimeZone "+tz.getDisplayName(false, TimeZone.SHORT)+" Timezone id :: " +tz.getID());
Output:
TimeZone GMT+09:30 Timezone id :: Australia/Darwin

- 7,978
- 3
- 36
- 36

- 5,513
- 2
- 27
- 29
-
-
1For me, the display name is only EST for TimeZone.SHORT, and Eastern Standard Time for TimeZone.LONG. All i'm looking for is the +/- value lol. Something must have changed. – FoxDonut Mar 23 '21 at 05:02
-
I needed the offset that not only included day light savings time but as a numerial. Here is the code that I used in case someone is looking for an example.
I get a response of "3.5" (3:30') which is what I would expect in Tehran , Iran in winter and "4.5" (4:30') for summer .
I also needed it as a string so I could post it to a server so you may not need the last line.
for getting currect time zone :
TimeZone tz = TimeZone.getDefault();
Date now = new Date();
//Import part : x.0 for double number
double offsetFromUtc = tz.getOffset(now.getTime()) / 3600000.0;
String m2tTimeZoneIs = Double.parseDouble(offsetFromUtc);

- 4,328
- 6
- 52
- 58
ZoneId from java.time and ThreeTenABP
Modern answer:
ZoneId zone = ZoneId.systemDefault();
System.out.println(zone);
When I ran this snippet in Australia/Sydney time zone, the output was exactly that:
Australia/Sydney
If you want the summer time (DST) aware time zone name or abbreviation:
DateTimeFormatter longTimeZoneFormatter = DateTimeFormatter.ofPattern("zzzz", Locale.getDefault());
String longTz = ZonedDateTime.now(zone).format(longTimeZoneFormatter);
System.out.println(longTz);
DateTimeFormatter shortTimeZoneFormatter = DateTimeFormatter.ofPattern("zzz", Locale.getDefault());
String shortTz = ZonedDateTime.now(zone).format(shortTimeZoneFormatter);
System.out.println(shortTz);
Eastern Summer Time (New South Wales) EST
The TimeZone
class used in most of the other answers was what we had when the question was asked in 2011, even though it was poorly designed. Today it’s long outdated, and I recommend that instead we use java.time, the modern Java date and time API that came out in 2014.
Question: Doesn’t java.time require Android API level 26?
java.time works nicely on both older and newer Android devices. It just requires at least Java 6.
- In Java 8 and later and on newer Android devices (from API level 26) the modern API comes built-in.
- In non-Android Java 6 and 7 get the ThreeTen Backport, the backport of the modern classes (ThreeTen for JSR 310; see the links at the bottom).
- Edit: On (older) Android usually, as long as you're on Android Gradle plugin 4.0 or newer, with
coreLibraryDesugaring
you can use java.time directly. ThreeTenABP is no longer needed. (Previous bullet: use the Android edition of ThreeTen Backport. It’s called ThreeTenABP. And make sure you import the date and time classes fromorg.threeten.bp
with subpackages.)
Links
- Oracle tutorial: Date Time explaining how to use java.time.
- Java Specification Request (JSR) 310, where
java.time
was first described. - ThreeTen Backport project, the backport of
java.time
to Java 6 and 7 (ThreeTen for JSR-310). - ThreeTenABP, Android edition of ThreeTen Backport
- Question: How to use ThreeTenABP in Android Project, with a very thorough explanation.

- 81,772
- 15
- 137
- 161
-
2Update to the API level 26 question. ThreeTenABP is no longer needed, usually, as long as you're on Android Gradle plugin 4.0 or newer. With `coreLibraryDesugaring` you can use java.time directly. – Jonik Mar 18 '21 at 10:25
Try this code-
Calendar cal = Calendar.getInstance();
TimeZone tz = cal.getTimeZone();
It will return user selected timezone.

- 6,263
- 7
- 52
- 86
-
4Creating a `Calendar` object for this is a nonsense. The creation of this type of object is expensive. `TimeZone.getDefault()` is the appropriate way to get this. – anonymous Apr 06 '13 at 09:41
-
3@KrLx_roller Please check carefully before downvoting answer. I have wrtitten my answer returns user selected timezone whereas TimeZone.getDefault() will return installation default time zone. For more info please http://code.google.com/p/android/issues/detail?id=2037. – anujprashar Apr 08 '13 at 10:35
-
Your code returns the same timezone as TimeZone.getDefault() on android 4.2. TimeZone.getDefault() will return the timezone selected in settings -> date & time. – idunno Nov 06 '13 at 14:51
TimeZone timeZone = TimeZone.getDefault();
timeZone.getID();
It will print like
Asia/Kolkata

- 8,084
- 8
- 48
- 62

- 6,742
- 9
- 45
- 56
On my device, TimeZone.getDefault()
is always returning the UTC time zone.
I need to do this to get the user-configured time zone:
TimeZone.setDefault(null)
val tz = TimeZone.getDefault()
It will return the user-selected time zone.

- 30,738
- 21
- 105
- 131

- 3,429
- 1
- 20
- 22
-
Was searching for hours, why `TimeZone.getDefault()` returns UTC always. Thanks for a solution. – Lybrica Apr 14 '23 at 10:15
Simplest Solution With Simple Date Format: SimpleDateFormat("ZZZZZ"):
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"),
Locale.getDefault());
Date currentLocalTime = calendar.getTime();
DateFormat date = new SimpleDateFormat("ZZZZZ",Locale.getDefault());
String localTime = date.format(currentLocalTime);
System.out.println(localTime+ " TimeZone " );
==> Output is : +05:30

- 1,536
- 17
- 20
All the answers here seem to suggest setting the daylight parameter to false. This is incorrect for many time zones which change abbreviated names depending on the time of the year (e.g., EST vs. EDT).
The solution below will give you the correct abbreviation according to the current date for the time zone.
val tz = TimeZone.getDefault()
val isDaylight = tz.inDaylightTime(Date())
val timezone = tz.getDisplayName(isDaylight, TimeZone.SHORT)

- 30,738
- 21
- 105
- 131

- 645
- 9
- 14
According to http://developer.android.com/reference/android/text/format/Time.html you should be using Time.getCurrentTimezone() to retrieve the current timezone of the device.

- 14,013
- 25
- 105
- 185
For devices with API 26 and higher, you can get it like this:
ZonedDateTime.now().getZone().toString();

- 3,218
- 1
- 24
- 26
I have spent some time to find the right answer. But it seems it works strangely on Android SDK. My device always returns 'UTC' as a timezoneId, and 0 as a timezone offset. But you can try to use headless WebView and fetch the timezone from there by JS. After this, you can save it into SharedPreference(TimeZone.setDefault()
also works strangely)
class HeadlessWebViewUtil constructor(context: Context) {
val webView = WebView(context)
val jsInterface = MyJavaScriptInterface()
fun fetch() {
webView.settings.javaScriptEnabled = true
webView.addJavascriptInterface(jsInterface, "android")
webView.loadUrl("javascript:android.onTimezoneFetched(Intl.DateTimeFormat().resolvedOptions().timeZone)")
}
inner class MyJavaScriptInterface {
@JavascriptInterface
public fun onTimezoneFetched(timezoneId: String) {
Timber.d("Timezone fetched: $timezoneId")
}
}
}
// And fetch
val wv = HeadlessWebViewUtil(this, timeZoneManager)
wv.fetch()

- 107
- 8