我正在尝试这样做
1. 获取我的当前时间和时区。
2. 我从 Google 知道该特定国家/地区的时区。
3. 计算时区差异。
4. 从当前时间中减去该差值。这会给我在其他国家的时间。
我被困在步骤 3 和 4 了。
我得到这样的当前时间
Date d = new Date();
CharSequence s = DateFormat.format("hh:mm:ss", d.getTime());
和这样的时区
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"),
Locale.getDefault());
Date currentLocalTime = calendar.getTime();
SimpleDateFormat date = new SimpleDateFormat("Z");
String localTime = date.format(currentLocalTime);
让特定国家的时区由字符串 x 表示。现在我如何获取 localTime - x 和 currentTime - (localTime - x)。
x 是时区 ID,有它们列表的链接。只需要向 gettimeZone("with the time zone id") 提供您想知道时间的城市的时区(我说的是城市,因为有些国家/地区有很多时区,例如美国或俄罗斯)。
时区 tz = TimeZone.getTimeZone("x")
http://garygregory.wordpress.com/2013/06/18/what-are-the-java-timezone-ids/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)