How to get the timezone offset in GMT(Like GMT+7:00) from android device?(如何从 Android 设备获取 GMT(如 GMT+7:00)的时区偏移量?)
问题描述
我正在使用此代码获取 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)的时区偏移量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 Android 设备获取 GMT(如 GMT+7:00)的时区偏移量?


基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01