本文整理汇总了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][]);
}
示例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");
}
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
}