本文整理了Java中java.time.zone.ZoneRules.isValidOffset()
方法的一些代码示例,展示了ZoneRules.isValidOffset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneRules.isValidOffset()
方法的具体详情如下:
包路径:java.time.zone.ZoneRules
类名称:ZoneRules
方法名:isValidOffset
[英]Checks if the offset date-time is valid for these rules.
To be valid, the local date-time must not be in a gap and the offset must match the valid offsets.
[中]检查偏移日期时间是否对这些规则有效。
要使其有效,本地日期时间不得处于间隙中,且偏移量必须与有效偏移量匹配。
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Resolves the offset into this zoned date-time.
* <p>
* This ignores the offset, unless it can be used in an overlap.
*
* @param offset the offset, not null
* @return the zoned date-time, not null
*/
private ZonedDateTime resolveOffset(ZoneOffset offset) {
if (offset.equals(this.offset) == false && zone.getRules().isValidOffset(dateTime, offset)) {
return new ZonedDateTime(dateTime, offset, zone);
}
return this;
}
代码示例来源:origin: infiniteautomation/ma-core-public
/**
* @param zdt
* @return
*/
public Instant getInstant(ZonedDateTime zdt) {
ZonedDateTime offset = zdt.withHour(hour).withMinute(minute).withSecond(second).withNano((int)(millisecond * 1000000l));
LocalDateTime ldt = zdt.toLocalDateTime();
ldt = ldt.withHour(hour).withMinute(minute).withSecond(second).withNano((int)(millisecond * 1000000l));
if(!zdt.getZone().getRules().isValidOffset(ldt, zdt.getOffset())) {
//Within a gap of DST so OR after the transition
ZoneOffsetTransition transition = zdt.getZone().getRules().nextTransition(zdt.toInstant());
if(!ldt.isAfter(transition.getDateTimeAfter())){
//In a gap so we shift our time forward to the end of the gap.
offset = transition.getDateTimeAfter().atZone(zdt.getZone());
}else {
//After a gap so ensure we use the next zone offset
offset = ldt.atOffset(transition.getOffsetAfter()).atZoneSimilarLocal(transition.getOffsetAfter());
}
}
return offset.toInstant();
}
}
代码示例来源:origin: com.github.seratch/java-time-backport
Jdk8Methods.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
if (rules.isValidOffset(localDateTime, offset) == false) {
ZoneOffsetTransition trans = rules.getTransition(localDateTime);
if (trans != null && trans.isGap()) {
内容来源于网络,如有侵权,请联系作者删除!