本文整理匯總了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);
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
}