我正在使用此代码获取 android 设备的 timezone
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))
但它总是像IST
"一样返回timezone
,但我想像GMT那样在
GMT
中获取时区+7:00.
But it always return me the timezone
like "IST
" but i want to get the timezone in GMT
like this GMT+7:00.
此代码返回我的 GMT 偏移量.
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);
它像这样返回时区偏移量:+0530
It returns the time zone offset like this: +0530
如果我们在下面使用 SimpleDateFormat
If we use SimpleDateFormat below
DateFormat date = new SimpleDateFormat("z",Locale.getDefault());
String localTime = date.format(currentLocalTime);
它像这样返回时区偏移量:GMT+05:30
It returns the time zone offset like this: GMT+05:30
这篇关于如何从 Android 设备获取 GMT(如 GMT+7:00)的时区偏移量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!