Android获取系统当前时区

public static String getTimeZone(){
    Calendar mDummyDate;
    mDummyDate = Calendar.getInstance();
    Calendar now = Calendar.getInstance();
    mDummyDate.setTimeZone(now.getTimeZone());
    mDummyDate.set(now.get(Calendar.YEAR), 11, 31, 13, 0, 0);
    return getTimeZoneText(now.getTimeZone(),true);
}

public static String getTimeZoneText(TimeZone tz, boolean includeName) {
    Date now = new Date();

    SimpleDateFormat gmtFormatter = new SimpleDateFormat("ZZZZ");
    gmtFormatter.setTimeZone(tz);
    String gmtString = gmtFormatter.format(now);
    BidiFormatter bidiFormatter = BidiFormatter.getInstance();
    Locale l = Locale.getDefault();
    boolean isRtl = TextUtils.getLayoutDirectionFromLocale(l) == View.LAYOUT_DIRECTION_RTL;
    gmtString = bidiFormatter.unicodeWrap(gmtString,
            isRtl ? TextDirectionHeuristics.RTL : TextDirectionHeuristics.LTR);

    if (!includeName) {
        return gmtString;
    }

    return gmtString;
}

你可能感兴趣的:(Android)