Naveen Kumar Naveen Kumar - 6 months ago 83
Android Question

How to get the timezone offset in GMT(Like GMT+7:00) from android device?

I am getting the

timezone
of a android device using this code

TimeZone tz = TimeZone.getDefault();
String current_Time_Zone = (TimeZone.getTimeZone(tz.getID()).getDisplayName(
false, TimeZone.SHORT))


But it always return me the
timezone
like "
IST
" but i want to get the timezone in
GMT
like this
GMT+7:00.

Please help me, Thanks.

Answer

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

Comments