当前位置: 首页>>代码示例>>Java>>正文


Java ZoneInfo类代码示例

本文整理汇总了Java中sun.util.calendar.ZoneInfo的典型用法代码示例。如果您正苦于以下问题:Java ZoneInfo类的具体用法?Java ZoneInfo怎么用?Java ZoneInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ZoneInfo类属于sun.util.calendar包,在下文中一共展示了ZoneInfo类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getZoneStrings

import sun.util.calendar.ZoneInfo; //导入依赖的package包/类
String[][] getZoneStrings() {
    TimeZoneNamesBundle rb = localeData.getTimeZoneNames(locale);
    Set<String> keyset = getZoneIDs();
    // Use a LinkedHashSet to preseve the order
    Set<String[]> value = new LinkedHashSet<>();
    for (String key : keyset) {
        value.add(rb.getStringArray(key));
    }

    // Add aliases data for CLDR
    if (type == LocaleProviderAdapter.Type.CLDR) {
        // Note: TimeZoneNamesBundle creates a String[] on each getStringArray call.
        Map<String, String> aliases = ZoneInfo.getAliasTable();
        for (String alias : aliases.keySet()) {
            if (!keyset.contains(alias)) {
                String tzid = aliases.get(alias);
                if (keyset.contains(tzid)) {
                    String[] val = rb.getStringArray(tzid);
                    val[0] = alias;
                    value.add(val);
                }
            }
        }
    }
    return value.toArray(new String[0][]);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:LocaleResources.java

示例2: main

import sun.util.calendar.ZoneInfo; //导入依赖的package包/类
public static void main(String[] args) {
    Map<String,String> map = ZoneInfo.getAliasTable();
    String alias = map.get("UTC");
    if (!alias.equals("Etc/UTC")) {
        throw new RuntimeException("got " + alias + ", expected Etc/UTC");
    }
    TimeZone GMT = TimeZone.getTimeZone("GMT");
    TimeZone UTC = TimeZone.getTimeZone("UTC");
    if (!GMT.hasSameRules(UTC)) {
        throw new RuntimeException("GMT and UTC have different rules");
    }
    TimeZone EtcUTC = TimeZone.getTimeZone("Etc/UTC");
    if (!UTC.hasSameRules(EtcUTC)) {
        throw new RuntimeException("UTC and Etc/UTC have different rules");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:UTCAliasTest.java

示例3: setTimeInMillis

import sun.util.calendar.ZoneInfo; //导入依赖的package包/类
/**
 * Sets this Calendar's current time from the given long value.
 *
 * @param millis the new time in UTC milliseconds from the epoch.
 * @see #setTime(Date)
 * @see #getTimeInMillis()
 */
public void setTimeInMillis(long millis) {
    // If we don't need to recalculate the calendar field values,
    // do nothing.
    if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet
        && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) {
        return;
    }
    time = millis;
    isTimeSet = true;
    areFieldsSet = false;
    computeFields();
    areAllFieldsSet = areFieldsSet = true;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:Calendar.java

示例4: writeObject

import sun.util.calendar.ZoneInfo; //导入依赖的package包/类
/**
 * Save the state of this object to a stream (i.e., serialize it).
 *
 * Ideally, <code>Calendar</code> would only write out its state data and
 * the current time, and not write any field data out, such as
 * <code>fields[]</code>, <code>isTimeSet</code>, <code>areFieldsSet</code>,
 * and <code>isSet[]</code>.  <code>nextStamp</code> also should not be part
 * of the persistent state. Unfortunately, this didn't happen before JDK 1.1
 * shipped. To be compatible with JDK 1.1, we will always have to write out
 * the field values and state flags.  However, <code>nextStamp</code> can be
 * removed from the serialization stream; this will probably happen in the
 * near future.
 */
private synchronized void writeObject(ObjectOutputStream stream)
     throws IOException
{
    // Try to compute the time correctly, for the future (stream
    // version 2) in which we don't write out fields[] or isSet[].
    if (!isTimeSet) {
        try {
            updateTime();
        }
        catch (IllegalArgumentException e) {}
    }

    // If this Calendar has a ZoneInfo, save it and set a
    // SimpleTimeZone equivalent (as a single DST schedule) for
    // backward compatibility.
    TimeZone savedZone = null;
    if (zone instanceof ZoneInfo) {
        SimpleTimeZone stz = ((ZoneInfo)zone).getLastRuleInstance();
        if (stz == null) {
            stz = new SimpleTimeZone(zone.getRawOffset(), zone.getID());
        }
        savedZone = zone;
        zone = stz;
    }

    // Write out the 1.1 FCS object.
    stream.defaultWriteObject();

    // Write out the ZoneInfo object
    // 4802409: we write out even if it is null, a temporary workaround
    // the real fix for bug 4844924 in corba-iiop
    stream.writeObject(savedZone);
    if (savedZone != null) {
        zone = savedZone;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:50,代码来源:Calendar.java

示例5: getTimeZone

import sun.util.calendar.ZoneInfo; //导入依赖的package包/类
private static DateTimeZone getTimeZone(String id) {
  DateTimeZone zone;
  try {
    zone = DateTimeZone.forID(id);
  } catch (IllegalArgumentException e) {
    TimeZone timeZone = ZoneInfo.getTimeZone(id);

    //throw error if unrecognized zone
    if (timeZone == null) {
      throw new IllegalArgumentException("TimeZone " + id + " not recognized");
    }
    zone = DateTimeZone.forTimeZone(timeZone);
  }
  return zone;
}
 
开发者ID:Hanmourang,项目名称:Gobblin,代码行数:16,代码来源:JsonElementConversionFactory.java

示例6: setTimeInMillis

import sun.util.calendar.ZoneInfo; //导入依赖的package包/类
/**
    * Sets this Calendar's current time from the given long value.
    *
    * @param millis the new time in UTC milliseconds from the epoch.
    * @see #setTime(Date)
    * @see #getTimeInMillis()
    */
   public void setTimeInMillis(long millis) {
// If we don't need to recalculate the calendar field values,
// do nothing.
if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet
    && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) {
    return;
}
       time = millis;
       isTimeSet = true;
       areFieldsSet = false;
computeFields();
       areAllFieldsSet = areFieldsSet = true;
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:21,代码来源:Calendar.java

示例7: writeObject

import sun.util.calendar.ZoneInfo; //导入依赖的package包/类
/**
    * Save the state of this object to a stream (i.e., serialize it).
    *
    * Ideally, <code>Calendar</code> would only write out its state data and
    * the current time, and not write any field data out, such as
    * <code>fields[]</code>, <code>isTimeSet</code>, <code>areFieldsSet</code>,
    * and <code>isSet[]</code>.  <code>nextStamp</code> also should not be part
    * of the persistent state. Unfortunately, this didn't happen before JDK 1.1
    * shipped. To be compatible with JDK 1.1, we will always have to write out
    * the field values and state flags.  However, <code>nextStamp</code> can be
    * removed from the serialization stream; this will probably happen in the
    * near future.
    */
   private void writeObject(ObjectOutputStream stream)
        throws IOException
   {
       // Try to compute the time correctly, for the future (stream
       // version 2) in which we don't write out fields[] or isSet[].
       if (!isTimeSet) {
           try {
               updateTime();
           }
           catch (IllegalArgumentException e) {}
       }

// If this Calendar has a ZoneInfo, save it and set a
// SimpleTimeZone equivalent (as a single DST schedule) for
// backward compatibility.
TimeZone savedZone = null;
if (zone instanceof ZoneInfo) {
    SimpleTimeZone stz = ((ZoneInfo)zone).getLastRuleInstance();
    if (stz == null) {
	stz = new SimpleTimeZone(zone.getRawOffset(), zone.getID());
    }
    savedZone = zone;
    zone = stz;
}

       // Write out the 1.1 FCS object.
       stream.defaultWriteObject();

// Write out the ZoneInfo object
// 4802409: we write out even if it is null, a temporary workaround
// the real fix for bug 4844924 in corba-iiop
stream.writeObject(savedZone);
if (savedZone != null) {
    zone = savedZone;
}
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:50,代码来源:Calendar.java

示例8: getTime

import sun.util.calendar.ZoneInfo; //导入依赖的package包/类
public long getTime(CalendarDate date) {
    long gd = getFixedDate(date);
    long ms = (gd - EPOCH_OFFSET) * DAY_IN_MILLIS + getTimeOfDay(date);
    int zoneOffset = 0;
    TimeZone zi = date.getZone();
    if (zi != null) {
        if (date.isNormalized()) {
            return ms - date.getZoneOffset();
        }
        // adjust time zone and daylight saving
        int[] offsets = new int[2];
        if (zi instanceof ZoneInfo) {
            zoneOffset = ((ZoneInfo)zi).getOffsetsByWall(ms, offsets);
        } else {
            zoneOffset = zi.getOffset(ms - zi.getRawOffset());
            offsets[0] = zi.getRawOffset();
            offsets[1] = zoneOffset - offsets[0];
        }
        if (date.forceDaylightTime() && offsets[1] == 0) {
            int amount = zi.getDSTSavings();
            if (amount == 0) {
                // workaround if this time zone doesn't observe
                // DST in its last rule. (6645292)
                amount = 60 * 60 * 1000;
            }
            zoneOffset += amount;
        }
    }
    ms -= zoneOffset;
    getCalendarDate(ms, date);
    return ms;
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:33,代码来源:AbstractCalendar.java

示例9: writeObject

import sun.util.calendar.ZoneInfo; //导入依赖的package包/类
/**
 * Save the state of this object to a stream (i.e., serialize it).
 *
 * Ideally, <code>Calendar</code> would only write out its state data and
 * the current time, and not write any field data out, such as
 * <code>fields[]</code>, <code>isTimeSet</code>, <code>areFieldsSet</code>,
 * and <code>isSet[]</code>.  <code>nextStamp</code> also should not be part
 * of the persistent state. Unfortunately, this didn't happen before JDK 1.1
 * shipped. To be compatible with JDK 1.1, we will always have to write out
 * the field values and state flags.  However, <code>nextStamp</code> can be
 * removed from the serialization stream; this will probably happen in the
 * near future.
 */
private void writeObject(ObjectOutputStream stream)
     throws IOException
{
    // Try to compute the time correctly, for the future (stream
    // version 2) in which we don't write out fields[] or isSet[].
    if (!isTimeSet) {
        try {
            updateTime();
        }
        catch (IllegalArgumentException e) {}
    }

    // If this Calendar has a ZoneInfo, save it and set a
    // SimpleTimeZone equivalent (as a single DST schedule) for
    // backward compatibility.
    TimeZone savedZone = null;
    if (zone instanceof ZoneInfo) {
        SimpleTimeZone stz = ((ZoneInfo)zone).getLastRuleInstance();
        if (stz == null) {
            stz = new SimpleTimeZone(zone.getRawOffset(), zone.getID());
        }
        savedZone = zone;
        zone = stz;
    }

    // Write out the 1.1 FCS object.
    stream.defaultWriteObject();

    // Write out the ZoneInfo object
    // 4802409: we write out even if it is null, a temporary workaround
    // the real fix for bug 4844924 in corba-iiop
    stream.writeObject(savedZone);
    if (savedZone != null) {
        zone = savedZone;
    }
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:50,代码来源:Calendar.java


注:本文中的sun.util.calendar.ZoneInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。