當前位置: 首頁>>代碼示例>>Java>>正文


Java TimeZone.getDSTSavings方法代碼示例

本文整理匯總了Java中java.util.TimeZone.getDSTSavings方法的典型用法代碼示例。如果您正苦於以下問題:Java TimeZone.getDSTSavings方法的具體用法?Java TimeZone.getDSTSavings怎麽用?Java TimeZone.getDSTSavings使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.TimeZone的用法示例。


在下文中一共展示了TimeZone.getDSTSavings方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getDisplayNameArray

import java.util.TimeZone; //導入方法依賴的package包/類
private String[] getDisplayNameArray(String id, Locale locale) {
    Objects.requireNonNull(id);
    Objects.requireNonNull(locale);

    String[] ret =
        LocaleProviderAdapter.forType(type).getLocaleResources(locale).getTimeZoneNames(id);

    if (Objects.nonNull(ret) && type == LocaleProviderAdapter.Type.CLDR) {
        // check for CLDR's "no inheritance marker"
        for (int index = 0; index < ret.length; index++) {
            TimeZone tz = null;
            if (CLDR_NO_INHERITANCE_MARKER.equals(ret[index])) {
                if (Objects.isNull(tz)) {
                    tz = TimeZone.getTimeZone(id);
                }
                int offset = tz.getRawOffset();
                if (index == 3 || index == 4) { // daylight
                    offset += tz.getDSTSavings();
                }
                ret[index] = ZoneInfoFile.toCustomID(offset);
            }
        }
    }

    return ret;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:TimeZoneNameProviderImpl.java

示例2: getTimeZone

import java.util.TimeZone; //導入方法依賴的package包/類
public static int getTimeZone() {

        TimeZone tz = TimeZone.getDefault();
        String displayName = tz.getDisplayName();
        int dstSavings = tz.getDSTSavings();
        String id = tz.getID();
        String displayName2 = tz.getDisplayName(false, TimeZone.SHORT);

        return 1;
    }
 
開發者ID:zeng3234,項目名稱:GrowingProject,代碼行數:11,代碼來源:DateUtils.java

示例3: createTimezoneDTO

import java.util.TimeZone; //導入方法依賴的package包/類
/**
    * Returns new <code>Timezone</code> object with populated values.
    *
    * @param timeZone
    * @param selected
    * @return
    */
   public static TimezoneDTO createTimezoneDTO(TimeZone timeZone, boolean selected) {
TimezoneDTO timezoneDTO = new TimezoneDTO();
timezoneDTO.timeZoneId = timeZone.getID();
int timeZoneRawOffset = timeZone.getRawOffset();
timezoneDTO.rawOffset = new Date(Math.abs(timeZoneRawOffset));
timezoneDTO.isRawOffsetNegative = timeZoneRawOffset < 0;
timezoneDTO.dstOffset = timeZone.getDSTSavings() / 60000;
timezoneDTO.displayName = timeZone.getDisplayName();
timezoneDTO.selected = selected;
return timezoneDTO;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:TimezoneDTO.java

示例4: subParseZoneString

import java.util.TimeZone; //導入方法依賴的package包/類
/**
 * find time zone 'text' matched zoneStrings and set to internal
 * calendar.
 */
private int subParseZoneString(String text, int start, CalendarBuilder calb) {
    boolean useSameName = false; // true if standard and daylight time use the same abbreviation.
    TimeZone currentTimeZone = getTimeZone();

    // At this point, check for named time zones by looking through
    // the locale data from the TimeZoneNames strings.
    // Want to be able to parse both short and long forms.
    int zoneIndex = formatData.getZoneIndex(currentTimeZone.getID());
    TimeZone tz = null;
    String[][] zoneStrings = formatData.getZoneStringsWrapper();
    String[] zoneNames = null;
    int nameIndex = 0;
    if (zoneIndex != -1) {
        zoneNames = zoneStrings[zoneIndex];
        if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
            if (nameIndex <= 2) {
                // Check if the standard name (abbr) and the daylight name are the same.
                useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
            }
            tz = TimeZone.getTimeZone(zoneNames[0]);
        }
    }
    if (tz == null) {
        zoneIndex = formatData.getZoneIndex(TimeZone.getDefault().getID());
        if (zoneIndex != -1) {
            zoneNames = zoneStrings[zoneIndex];
            if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
                if (nameIndex <= 2) {
                    useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
                }
                tz = TimeZone.getTimeZone(zoneNames[0]);
            }
        }
    }

    if (tz == null) {
        int len = zoneStrings.length;
        for (int i = 0; i < len; i++) {
            zoneNames = zoneStrings[i];
            if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
                if (nameIndex <= 2) {
                    useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
                }
                tz = TimeZone.getTimeZone(zoneNames[0]);
                break;
            }
        }
    }
    if (tz != null) { // Matched any ?
        if (!tz.equals(currentTimeZone)) {
            setTimeZone(tz);
        }
        // If the time zone matched uses the same name
        // (abbreviation) for both standard and daylight time,
        // let the time zone in the Calendar decide which one.
        //
        // Also if tz.getDSTSaving() returns 0 for DST, use tz to
        // determine the local time. (6645292)
        int dstAmount = (nameIndex >= 3) ? tz.getDSTSavings() : 0;
        if (!(useSameName || (nameIndex >= 3 && dstAmount == 0))) {
            calb.clear(Calendar.ZONE_OFFSET).set(Calendar.DST_OFFSET, dstAmount);
        }
        return (start + zoneNames[nameIndex].length());
    }
    return 0;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:71,代碼來源:SimpleDateFormat.java

示例5: subParseZoneString

import java.util.TimeZone; //導入方法依賴的package包/類
/**
 * find time zone 'text' matched zoneStrings and set to internal
 * calendar.
 */
private int subParseZoneString(String text, int start, CalendarBuilder calb) {
    boolean useSameName = false; // true if standard and daylight time use the same abbreviation.
    TimeZone currentTimeZone = getTimeZone();

    // At this point, check for named time zones by looking through
    // the locale data from the TimeZoneNames strings.
    // Want to be able to parse both short and long forms.
    int zoneIndex = formatData.getZoneIndex(currentTimeZone.getID());
    TimeZone tz = null;
    String[][] zoneStrings = formatData.getZoneStringsWrapper();
    String[] zoneNames = null;
    int nameIndex = 0;
    if (zoneIndex != -1) {
        zoneNames = zoneStrings[zoneIndex];
        if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
            if (nameIndex <= 2) {
                // Check if the standard name (abbr) and the daylight name are the same.
                useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
            }
            tz = TimeZone.getTimeZone(zoneNames[0]);
        }
    }
    if (tz == null) {
        zoneIndex = formatData.getZoneIndex(TimeZone.getDefault().getID());
        if (zoneIndex != -1) {
            zoneNames = zoneStrings[zoneIndex];
            if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
                if (nameIndex <= 2) {
                    useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
                }
                tz = TimeZone.getTimeZone(zoneNames[0]);
            }
        }
    }

    if (tz == null) {
        int len = zoneStrings.length;
        for (int i = 0; i < len; i++) {
            zoneNames = zoneStrings[i];
            if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
                if (nameIndex <= 2) {
                    useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
                }
                tz = TimeZone.getTimeZone(zoneNames[0]);
                break;
            }
        }
    }
    if (tz != null) { // Matched any ?
        if (!tz.equals(currentTimeZone)) {
            setTimeZone(tz);
        }
        // If the time zone matched uses the same name
        // (abbreviation) for both standard and daylight time,
        // let the time zone in the Calendar decide which one.
        //
        // Also if tz.getDSTSaving() returns 0 for DST, use tz to
        // determine the local time. (6645292)
        int dstAmount = (nameIndex >= 3) ? tz.getDSTSavings() : 0;
        if (!(useSameName || (nameIndex >= 3 && dstAmount == 0))) {
            calb.clear(Calendar.ZONE_OFFSET).set(Calendar.DST_OFFSET, dstAmount);
        }
        return (start + zoneNames[nameIndex].length());
    }
    return -start;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:71,代碼來源:SimpleDateFormat.java


注:本文中的java.util.TimeZone.getDSTSavings方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。