赞
踩
Android手机中如果想以GMT形式(GMT+08:00)得到当前时区,可以参照如下代码所示:
- public static String getCurrentTimeZone()
- {
- TimeZone tz = TimeZone.getDefault();
- return createGmtOffsetString(true,true,tz.getRawOffset());
- }
- public static String createGmtOffsetString(boolean includeGmt,
- boolean includeMinuteSeparator, int offsetMillis) {
- int offsetMinutes = offsetMillis / 60000;
- char sign = '+';
- if (offsetMinutes < 0) {
- sign = '-';
- offsetMinutes = -offsetMinutes;
- }
- StringBuilder builder = new StringBuilder(9);
- if (includeGmt) {
- builder.append("GMT");
- }
- builder.append(sign);
- appendNumber(builder, 2, offsetMinutes / 60);
- if (includeMinuteSeparator) {
- builder.append(':');
- }
- appendNumber(builder, 2, offsetMinutes % 60);
- return builder.toString();
- }
-
- private static void appendNumber(StringBuilder builder, int count, int value) {
- String string = Integer.toString(value);
- for (int i = 0; i < count - string.length(); i++) {
- builder.append('0');
- }
- builder.append(string);
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。