本文整理汇总了Java中java.time.zone.ZoneOffsetTransitionRule.getStandardOffset方法的典型用法代码示例。如果您正苦于以下问题:Java ZoneOffsetTransitionRule.getStandardOffset方法的具体用法?Java ZoneOffsetTransitionRule.getStandardOffset怎么用?Java ZoneOffsetTransitionRule.getStandardOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.zone.ZoneOffsetTransitionRule
的用法示例。
在下文中一共展示了ZoneOffsetTransitionRule.getStandardOffset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeRule
import java.time.zone.ZoneOffsetTransitionRule; //导入方法依赖的package包/类
/**
* Writes the state of the transition rule to the stream.
*
* @param rule the transition rule, not null
* @param out the output stream, not null
* @throws IOException if an error occurs
*/
static void writeRule(ZoneOffsetTransitionRule rule, DataOutput out) throws IOException {
int month = rule.getMonth().getValue();
byte dom = (byte)rule.getDayOfMonthIndicator();
int dow = (rule.getDayOfWeek() == null ? -1 : rule.getDayOfWeek().getValue());
LocalTime time = rule.getLocalTime();
boolean timeEndOfDay = rule.isMidnightEndOfDay();
TimeDefinition timeDefinition = rule.getTimeDefinition();
ZoneOffset standardOffset = rule.getStandardOffset();
ZoneOffset offsetBefore = rule.getOffsetBefore();
ZoneOffset offsetAfter = rule.getOffsetAfter();
int timeSecs = (timeEndOfDay ? 86400 : time.toSecondOfDay());
int stdOffset = standardOffset.getTotalSeconds();
int beforeDiff = offsetBefore.getTotalSeconds() - stdOffset;
int afterDiff = offsetAfter.getTotalSeconds() - stdOffset;
int timeByte = (timeSecs % 3600 == 0 ? (timeEndOfDay ? 24 : time.getHour()) : 31);
int stdOffsetByte = (stdOffset % 900 == 0 ? stdOffset / 900 + 128 : 255);
int beforeByte = (beforeDiff == 0 || beforeDiff == 1800 || beforeDiff == 3600 ? beforeDiff / 1800 : 3);
int afterByte = (afterDiff == 0 || afterDiff == 1800 || afterDiff == 3600 ? afterDiff / 1800 : 3);
int dowByte = (dow == -1 ? 0 : dow);
int b = (month << 28) + // 4 bytes
((dom + 32) << 22) + // 6 bytes
(dowByte << 19) + // 3 bytes
(timeByte << 14) + // 5 bytes
(timeDefinition.ordinal() << 12) + // 2 bytes
(stdOffsetByte << 4) + // 8 bytes
(beforeByte << 2) + // 2 bytes
afterByte; // 2 bytes
out.writeInt(b);
if (timeByte == 31) {
out.writeInt(timeSecs);
}
if (stdOffsetByte == 255) {
out.writeInt(stdOffset);
}
if (beforeByte == 3) {
out.writeInt(offsetBefore.getTotalSeconds());
}
if (afterByte == 3) {
out.writeInt(offsetAfter.getTotalSeconds());
}
}