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)的时区偏移量?


- Android - 拆分 Drawable 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01