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


Java TimeZone.hasSameRules方法代碼示例

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


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

示例1: convert

import java.util.TimeZone; //導入方法依賴的package包/類
private static DateTimeValue convert(DateTimeValue time,
                                     TimeZone zone,
                                     int sense) {
    if (zone == null ||
            zone.hasSameRules(ZULU) ||
            time.year() == 0) {
        return time;
    }

    long timetMillis = 0;

    if (sense > 0) {
        // time is in UTC
        timetMillis = timetMillisFromEpochSecs(secsSinceEpoch(time), ZULU);
    } else {
        // time is in local time; since zone.getOffset() expects millis
        // in UTC, need to convert before we can get the offset (ironic)
        timetMillis = timetMillisFromEpochSecs(secsSinceEpoch(time), zone);
    }

    int millisecondOffset = zone.getOffset(timetMillis);
    int millisecondRound = millisecondOffset < 0 ? -500 : 500;
    int secondOffset = (millisecondOffset + millisecondRound) / 1000;
    return addSeconds(time, sense * secondOffset);
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:26,代碼來源:TimeUtils.java

示例2: timeZoneForName

import java.util.TimeZone; //導入方法依賴的package包/類
/**
 * returns the timezone with the given name or null if no such timezone.
 * calendar/common/ICalUtil uses this function
 */
public static TimeZone timeZoneForName(String tzString) {
    // This is a horrible hack since there is no easier way to get a timezone
    // only if the string is recognized as a timezone.
    // The TimeZone.getTimeZone javadoc says the following:
    //   Returns:
    //       the specified TimeZone, or the GMT zone if the given ID cannot be
    //       understood.
    TimeZone tz = TimeZone.getTimeZone(tzString);
    if (tz.hasSameRules(BOGUS_TIMEZONE)) {
        // see if the user really was asking for GMT because if
        // TimeZone.getTimeZone can't recognize tzString, then that is what it
        // will return.
        Matcher m = UTC_TZID.matcher(tzString);
        if (m.matches()) {
            return TimeUtils.utcTimezone();
        }
        // unrecognizable timezone
        return null;
    }
    return tz;
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:26,代碼來源:TimeUtils.java

示例3: readObject

import java.util.TimeZone; //導入方法依賴的package包/類
/**
 * After reading an object from the input stream, the format
 * pattern in the object is verified.
 * <p>
 * @exception InvalidObjectException if the pattern is invalid
 */
private void readObject(ObjectInputStream stream)
                     throws IOException, ClassNotFoundException {
    stream.defaultReadObject();

    try {
        compiledPattern = compile(pattern);
    } catch (Exception e) {
        throw new InvalidObjectException("invalid pattern");
    }

    if (serialVersionOnStream < 1) {
        // didn't have defaultCenturyStart field
        initializeDefaultCentury();
    }
    else {
        // fill in dependent transient field
        parseAmbiguousDatesAsAfter(defaultCenturyStart);
    }
    serialVersionOnStream = currentSerialVersion;

    // If the deserialized object has a SimpleTimeZone, try
    // to replace it with a ZoneInfo equivalent in order to
    // be compatible with the SimpleTimeZone-based
    // implementation as much as possible.
    TimeZone tz = getTimeZone();
    if (tz instanceof SimpleTimeZone) {
        String id = tz.getID();
        TimeZone zi = TimeZone.getTimeZone(id);
        if (zi != null && zi.hasSameRules(tz) && zi.getID().equals(id)) {
            setTimeZone(zi);
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:40,代碼來源:SimpleDateFormat.java

示例4: readObject

import java.util.TimeZone; //導入方法依賴的package包/類
/**
 * After reading an object from the input stream, the format
 * pattern in the object is verified.
 *
 * @exception InvalidObjectException if the pattern is invalid
 */
private void readObject(ObjectInputStream stream)
                     throws IOException, ClassNotFoundException {
    stream.defaultReadObject();

    try {
        compiledPattern = compile(pattern);
    } catch (Exception e) {
        throw new InvalidObjectException("invalid pattern");
    }

    if (serialVersionOnStream < 1) {
        // didn't have defaultCenturyStart field
        initializeDefaultCentury();
    }
    else {
        // fill in dependent transient field
        parseAmbiguousDatesAsAfter(defaultCenturyStart);
    }
    serialVersionOnStream = currentSerialVersion;

    // If the deserialized object has a SimpleTimeZone, try
    // to replace it with a ZoneInfo equivalent in order to
    // be compatible with the SimpleTimeZone-based
    // implementation as much as possible.
    TimeZone tz = getTimeZone();
    if (tz instanceof SimpleTimeZone) {
        String id = tz.getID();
        TimeZone zi = TimeZone.getTimeZone(id);
        if (zi != null && zi.hasSameRules(tz) && zi.getID().equals(id)) {
            setTimeZone(zi);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:40,代碼來源:SimpleDateFormat.java


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