如何获得时区在格林尼治标准​​时间(像GMT + 7:00)抵消了Android设备? [英] How to get the timezone offset in GMT(Like GMT+7:00) from android device?

查看:470
本文介绍了如何获得时区在格林尼治标准​​时间(像GMT + 7:00)抵消了Android设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到时区一个Android设备的用这个code

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))

但它总是返回我的时区北京时间但我想要得到的时区中的 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. Please help me, Thanks.

推荐答案

这code回到我的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

这篇关于如何获得时区在格林尼治标准​​时间(像GMT + 7:00)抵消了Android设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆