本文整理了Java中org.threeten.bp.zone.ZoneRules.getTransition()
方法的一些代码示例,展示了ZoneRules.getTransition()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneRules.getTransition()
方法的具体详情如下:
包路径:org.threeten.bp.zone.ZoneRules
类名称:ZoneRules
方法名:getTransition
[英]Gets the offset transition applicable at the specified local date-time in these rules.
The mapping from a local date-time to an offset is not straightforward. There are three cases:
A transition is used to model the cases of a Gap or Overlap. The Normal case will return null.
There are various ways to handle the conversion from a LocalDateTime. One technique, using this method, would be:
ZoneOffsetTransition trans = rules.getTransition(localDT);
if (trans == null) {
// Gap or Overlap: determine what to do from transition
} else {
// Normal case: only one valid offset
zoneOffset = rule.getOffset(localDT);
}
[中]获取在这些规则中指定的本地日期时间适用的偏移量转换。
从本地日期时间到偏移量的映射并不简单。有三种情况:
*正常,有一个有效偏移。对于一年中的绝大多数时间,正常情况适用,当地日期和时间只有一个有效的偏移量。
*间隙,具有零有效偏移。这通常是由于春季夏令时从“冬季”变为“夏季”,时钟向前跳的时候。在间隙中,存在没有有效偏移的本地日期时间值。
*重叠,具有两个有效偏移。这是因为秋季夏令时从“夏季”变为“冬季”,时钟通常会被延迟。在重叠中,有两个有效偏移的本地日期时间值。
过渡用于模拟间隙或重叠的情况。正常情况下将返回null。
有多种方法可以处理LocalDateTime的转换。使用这种方法的一种技术是:
ZoneOffsetTransition trans = rules.getTransition(localDT);
if (trans == null) {
// Gap or Overlap: determine what to do from transition
} else {
// Normal case: only one valid offset
zoneOffset = rule.getOffset(localDT);
}
代码示例来源:origin: stackoverflow.com
LocalDateTime ldt = LocalDateTime.of(2015, 3, 29, 2, 30, 0, 0);
ZoneRules rules = ZoneId.of("Europe/Berlin").getRules();
ZoneOffsetTransition conflict = rules.getTransition(ldt);
if (conflict != null && conflict.isGap()) {
ldt = conflict.getDateTimeAfter();
}
System.out.println(ldt); // 2015-03-29T03:00
代码示例来源:origin: org.threeten/threetenbp
@Override
public ChronoZonedDateTime<D> withEarlierOffsetAtOverlap() {
ZoneOffsetTransition trans = getZone().getRules().getTransition(LocalDateTime.from(this));
if (trans != null && trans.isOverlap()) {
ZoneOffset earlierOffset = trans.getOffsetBefore();
if (earlierOffset.equals(offset) == false) {
return new ChronoZonedDateTimeImpl<D>(dateTime, earlierOffset, zone);
}
}
return this;
}
代码示例来源:origin: org.threeten/threetenbp
offset = validOffsets.get(0);
} else if (validOffsets.size() == 0) {
ZoneOffsetTransition trans = rules.getTransition(isoLDT);
localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds());
offset = trans.getOffsetAfter();
代码示例来源:origin: ThreeTen/threetenbp
@Override
public ChronoZonedDateTime<D> withLaterOffsetAtOverlap() {
ZoneOffsetTransition trans = getZone().getRules().getTransition(LocalDateTime.from(this));
if (trans != null) {
ZoneOffset offset = trans.getOffsetAfter();
if (offset.equals(getOffset()) == false) {
return new ChronoZonedDateTimeImpl<D>(dateTime, offset, zone);
}
}
return this;
}
代码示例来源:origin: ThreeTen/threetenbp
offset = validOffsets.get(0);
} else if (validOffsets.size() == 0) {
ZoneOffsetTransition trans = rules.getTransition(isoLDT);
localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds());
offset = trans.getOffsetAfter();
代码示例来源:origin: org.threeten/threetenbp
offset = validOffsets.get(0);
} else if (validOffsets.size() == 0) {
ZoneOffsetTransition trans = rules.getTransition(localDateTime);
localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds());
offset = trans.getOffsetAfter();
代码示例来源:origin: ThreeTen/threetenbp
@Override
public ChronoZonedDateTime<D> withEarlierOffsetAtOverlap() {
ZoneOffsetTransition trans = getZone().getRules().getTransition(LocalDateTime.from(this));
if (trans != null && trans.isOverlap()) {
ZoneOffset earlierOffset = trans.getOffsetBefore();
if (earlierOffset.equals(offset) == false) {
return new ChronoZonedDateTimeImpl<D>(dateTime, earlierOffset, zone);
}
}
return this;
}
代码示例来源:origin: ThreeTen/threetenbp
offset = validOffsets.get(0);
} else if (validOffsets.size() == 0) {
ZoneOffsetTransition trans = rules.getTransition(localDateTime);
localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds());
offset = trans.getOffsetAfter();
代码示例来源:origin: org.threeten/threetenbp
@Override
public ChronoZonedDateTime<D> withLaterOffsetAtOverlap() {
ZoneOffsetTransition trans = getZone().getRules().getTransition(LocalDateTime.from(this));
if (trans != null) {
ZoneOffset offset = trans.getOffsetAfter();
if (offset.equals(getOffset()) == false) {
return new ChronoZonedDateTimeImpl<D>(dateTime, offset, zone);
}
}
return this;
}
代码示例来源:origin: ThreeTen/threetenbp
/**
* Returns a copy of this date-time changing the zone offset to the
* earlier of the two valid offsets at a local time-line overlap.
* <p>
* This method only has any effect when the local time-line overlaps, such as
* at an autumn daylight savings cutover. In this scenario, there are two
* valid offsets for the local date-time. Calling this method will return
* a zoned date-time with the earlier of the two selected.
* <p>
* If this method is called when it is not an overlap, {@code this}
* is returned.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @return a {@code ZonedDateTime} based on this date-time with the earlier offset, not null
*/
@Override
public ZonedDateTime withEarlierOffsetAtOverlap() {
ZoneOffsetTransition trans = getZone().getRules().getTransition(dateTime);
if (trans != null && trans.isOverlap()) {
ZoneOffset earlierOffset = trans.getOffsetBefore();
if (earlierOffset.equals(offset) == false) {
return new ZonedDateTime(dateTime, earlierOffset, zone);
}
}
return this;
}
代码示例来源:origin: ThreeTen/threetenbp
/**
* Returns a copy of this date-time changing the zone offset to the
* later of the two valid offsets at a local time-line overlap.
* <p>
* This method only has any effect when the local time-line overlaps, such as
* at an autumn daylight savings cutover. In this scenario, there are two
* valid offsets for the local date-time. Calling this method will return
* a zoned date-time with the later of the two selected.
* <p>
* If this method is called when it is not an overlap, {@code this}
* is returned.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @return a {@code ZonedDateTime} based on this date-time with the later offset, not null
*/
@Override
public ZonedDateTime withLaterOffsetAtOverlap() {
ZoneOffsetTransition trans = getZone().getRules().getTransition(toLocalDateTime());
if (trans != null) {
ZoneOffset laterOffset = trans.getOffsetAfter();
if (laterOffset.equals(offset) == false) {
return new ZonedDateTime(dateTime, laterOffset, zone);
}
}
return this;
}
代码示例来源:origin: org.threeten/threetenbp
/**
* Returns a copy of this date-time changing the zone offset to the
* earlier of the two valid offsets at a local time-line overlap.
* <p>
* This method only has any effect when the local time-line overlaps, such as
* at an autumn daylight savings cutover. In this scenario, there are two
* valid offsets for the local date-time. Calling this method will return
* a zoned date-time with the earlier of the two selected.
* <p>
* If this method is called when it is not an overlap, {@code this}
* is returned.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @return a {@code ZonedDateTime} based on this date-time with the earlier offset, not null
*/
@Override
public ZonedDateTime withEarlierOffsetAtOverlap() {
ZoneOffsetTransition trans = getZone().getRules().getTransition(dateTime);
if (trans != null && trans.isOverlap()) {
ZoneOffset earlierOffset = trans.getOffsetBefore();
if (earlierOffset.equals(offset) == false) {
return new ZonedDateTime(dateTime, earlierOffset, zone);
}
}
return this;
}
代码示例来源:origin: org.threeten/threetenbp
/**
* Returns a copy of this date-time changing the zone offset to the
* later of the two valid offsets at a local time-line overlap.
* <p>
* This method only has any effect when the local time-line overlaps, such as
* at an autumn daylight savings cutover. In this scenario, there are two
* valid offsets for the local date-time. Calling this method will return
* a zoned date-time with the later of the two selected.
* <p>
* If this method is called when it is not an overlap, {@code this}
* is returned.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @return a {@code ZonedDateTime} based on this date-time with the later offset, not null
*/
@Override
public ZonedDateTime withLaterOffsetAtOverlap() {
ZoneOffsetTransition trans = getZone().getRules().getTransition(toLocalDateTime());
if (trans != null) {
ZoneOffset laterOffset = trans.getOffsetAfter();
if (laterOffset.equals(offset) == false) {
return new ZonedDateTime(dateTime, laterOffset, zone);
}
}
return this;
}
代码示例来源:origin: org.threeten/threetenbp
if (zone instanceof ZoneOffset == false) {
ZoneRules rules = zone.getRules();
ZoneOffsetTransition trans = rules.getTransition(ldt);
if (trans != null && trans.isGap()) {
ldt = trans.getDateTimeAfter();
代码示例来源:origin: ThreeTen/threetenbp
if (zone instanceof ZoneOffset == false) {
ZoneRules rules = zone.getRules();
ZoneOffsetTransition trans = rules.getTransition(ldt);
if (trans != null && trans.isGap()) {
ldt = trans.getDateTimeAfter();
代码示例来源:origin: ThreeTen/threetenbp
ZoneRules rules = zone.getRules();
if (rules.isValidOffset(localDateTime, offset) == false) {
ZoneOffsetTransition trans = rules.getTransition(localDateTime);
if (trans != null && trans.isGap()) {
代码示例来源:origin: org.threeten/threetenbp
ZoneRules rules = zone.getRules();
if (rules.isValidOffset(localDateTime, offset) == false) {
ZoneOffsetTransition trans = rules.getTransition(localDateTime);
if (trans != null && trans.isGap()) {
内容来源于网络,如有侵权,请联系作者删除!