gpt4 book ai didi

android - 如何在 GMT 中获取时区偏移量(如 GMT+7 :00) from android device?

转载 作者:IT王子 更新时间:2023-10-28 23:51:01 30 4
gpt4 key购买 nike

我正在使用此代码获取 android 设备的 timezone

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

但它总是像“IST”一样返回timezone,但我想像这样GMT 获取GMT 中的时区+7:00。

最佳答案

这可能会让您了解如何根据自己的喜好实现它:

Calendar mCalendar = new GregorianCalendar();  
TimeZone mTimeZone = mCalendar.getTimeZone();
int mGMTOffset = mTimeZone.getRawOffset();
System.out.printf("GMT offset is %s hours", TimeUnit.HOURS.convert(mGMTOffset, TimeUnit.MILLISECONDS));

(时间单位是“java.util.concurrent.TimeUnit”)

关于android - 如何在 GMT 中获取时区偏移量(如 GMT+7 :00) from android device?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15068113/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com