本文整理汇总了Java中java.time.zone.ZoneRules.isValidOffset方法的典型用法代码示例。如果您正苦于以下问题:Java ZoneRules.isValidOffset方法的具体用法?Java ZoneRules.isValidOffset怎么用?Java ZoneRules.isValidOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.zone.ZoneRules
的用法示例。
在下文中一共展示了ZoneRules.isValidOffset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ofStrict
import java.time.zone.ZoneRules; //导入方法依赖的package包/类
/**
* Obtains an instance of {@code ZonedDateTime} strictly validating the
* combination of local date-time, offset and zone ID.
* <p>
* This creates a zoned date-time ensuring that the offset is valid for the
* local date-time according to the rules of the specified zone.
* If the offset is invalid, an exception is thrown.
*
* @param localDateTime the local date-time, not null
* @param offset the zone offset, not null
* @param zone the time-zone, not null
* @return the zoned date-time, not null
*/
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
Objects.requireNonNull(localDateTime, "localDateTime");
Objects.requireNonNull(offset, "offset");
Objects.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
if (rules.isValidOffset(localDateTime, offset) == false) {
ZoneOffsetTransition trans = rules.getTransition(localDateTime);
if (trans != null && trans.isGap()) {
// error message says daylight savings for simplicity
// even though there are other kinds of gaps
throw new DateTimeException("LocalDateTime '" + localDateTime +
"' does not exist in zone '" + zone +
"' due to a gap in the local time-line, typically caused by daylight savings");
}
throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
localDateTime + "' in zone '" + zone + "'");
}
return new ZonedDateTime(localDateTime, offset, zone);
}
示例2: ofStrict
import java.time.zone.ZoneRules; //导入方法依赖的package包/类
/**
* Obtains an instance of {@code ZonedDateTime} strictly validating the combination of local date-time,
* offset and zone ID.
* <p>
* This creates a zoned date-time ensuring that the offset is valid for the local date-time according to the
* rules of the specified zone. If the offset is invalid, an exception is thrown.
*
* @param localDateTime the local date-time, not null
* @param offset the zone offset, not null
* @param zone the time-zone, not null
* @return the zoned date-time, not null
*/
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
Jdk7Methods.Objects_requireNonNull(localDateTime, "localDateTime");
Jdk7Methods.Objects_requireNonNull(offset, "offset");
Jdk7Methods.Objects_requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
if (rules.isValidOffset(localDateTime, offset) == false) {
// ZoneOffsetTransition trans = rules.getTransition(localDateTime);
// if (trans != null && trans.isGap()) {
// // error message says daylight savings for simplicity
// // even though there are other kinds of gaps
// throw new DateTimeException("LocalDateTime '" + localDateTime + "' does not exist in zone '" + zone
// + "' due to a gap in the local time-line, typically caused by daylight savings");
// }
// throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
// localDateTime
// + "' in zone '" + zone + "'");
}
return new ZonedDateTime(localDateTime, offset, zone);
}
示例3: ofStrict
import java.time.zone.ZoneRules; //导入方法依赖的package包/类
/**
* Obtains an instance of {@code ZonedDateTime} strictly validating the
* combination of local date-time, offset and zone ID.
* <p>
* This creates a zoned date-time ensuring that the offset is valid for the
* local date-time according to the rules of the specified zone.
* If the offset is invalid, an exception is thrown.
*
* @param localDateTime the local date-time, not null
* @param offset the zone offset, not null
* @param zone the time-zone, not null
* @return the zoned date-time, not null
* @throws DateTimeException if the combination of arguments is invalid
*/
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
Objects.requireNonNull(localDateTime, "localDateTime");
Objects.requireNonNull(offset, "offset");
Objects.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
if (rules.isValidOffset(localDateTime, offset) == false) {
ZoneOffsetTransition trans = rules.getTransition(localDateTime);
if (trans != null && trans.isGap()) {
// error message says daylight savings for simplicity
// even though there are other kinds of gaps
throw new DateTimeException("LocalDateTime '" + localDateTime +
"' does not exist in zone '" + zone +
"' due to a gap in the local time-line, typically caused by daylight savings");
}
throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
localDateTime + "' in zone '" + zone + "'");
}
return new ZonedDateTime(localDateTime, offset, zone);
}