当前位置: 首页>>代码示例>>Java>>正文


Java ZoneOffset.getTotalSeconds方法代码示例

本文整理汇总了Java中java.time.ZoneOffset.getTotalSeconds方法的典型用法代码示例。如果您正苦于以下问题:Java ZoneOffset.getTotalSeconds方法的具体用法?Java ZoneOffset.getTotalSeconds怎么用?Java ZoneOffset.getTotalSeconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.ZoneOffset的用法示例。


在下文中一共展示了ZoneOffset.getTotalSeconds方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeOffset

import java.time.ZoneOffset; //导入方法依赖的package包/类
/**
 * Writes the state to the stream.
 *
 * @param offset  the offset, not null
 * @param out  the output stream, not null
 * @throws IOException if an error occurs
 */
static void writeOffset(ZoneOffset offset, DataOutput out) throws IOException {
    final int offsetSecs = offset.getTotalSeconds();
    int offsetByte = offsetSecs % 900 == 0 ? offsetSecs / 900 : 127;  // compress to -72 to +72
    out.writeByte(offsetByte);
    if (offsetByte == 127) {
        out.writeInt(offsetSecs);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:Ser.java

示例2: toEpochSecond

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Override
public long toEpochSecond(ZoneOffset offset) {

  Jdk7Methods.Objects_requireNonNull(offset, "offset");
  long epochDay = getDate().toEpochDay();
  long secs = epochDay * 86400 + getTime().toSecondOfDay();
  secs -= offset.getTotalSeconds();
  return secs;
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:10,代码来源:DefaultInterfaceChronoLocalDateTime.java

示例3: writeOffset

import java.time.ZoneOffset; //导入方法依赖的package包/类
/**
 * Writes the state the ZoneOffset to the stream.
 *
 * @param offset  the offset, not null
 * @param out  the output stream, not null
 * @throws IOException if an error occurs
 */
static void writeOffset(ZoneOffset offset, DataOutput out) throws IOException {
    final int offsetSecs = offset.getTotalSeconds();
    int offsetByte = offsetSecs % 900 == 0 ? offsetSecs / 900 : 127;  // compress to -72 to +72
    out.writeByte(offsetByte);
    if (offsetByte == 127) {
        out.writeInt(offsetSecs);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ZoneRules.java

示例4: getOffsetInfo

import java.time.ZoneOffset; //导入方法依赖的package包/类
private Object getOffsetInfo(LocalDateTime dt) {
    if (savingsInstantTransitions.length == 0) {
        return standardOffsets[0];
    }
    // check if using last rules
    if (lastRules.length > 0 &&
            dt.isAfter(savingsLocalTransitions[savingsLocalTransitions.length - 1])) {
        ZoneOffsetTransition[] transArray = findTransitionArray(dt.getYear());
        Object info = null;
        for (ZoneOffsetTransition trans : transArray) {
            info = findOffsetInfo(dt, trans);
            if (info instanceof ZoneOffsetTransition || info.equals(trans.getOffsetBefore())) {
                return info;
            }
        }
        return info;
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsLocalTransitions, dt);
    if (index == -1) {
        // before first transition
        return wallOffsets[0];
    }
    if (index < 0) {
        // switch negative insert position to start of matched range
        index = -index - 2;
    } else if (index < savingsLocalTransitions.length - 1 &&
            savingsLocalTransitions[index].equals(savingsLocalTransitions[index + 1])) {
        // handle overlap immediately following gap
        index++;
    }
    if ((index & 1) == 0) {
        // gap or overlap
        LocalDateTime dtBefore = savingsLocalTransitions[index];
        LocalDateTime dtAfter = savingsLocalTransitions[index + 1];
        ZoneOffset offsetBefore = wallOffsets[index / 2];
        ZoneOffset offsetAfter = wallOffsets[index / 2 + 1];
        if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) {
            // gap
            return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter);
        } else {
            // overlap
            return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);
        }
    } else {
        // normal (neither gap or overlap)
        return wallOffsets[index / 2 + 1];
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:51,代码来源:ZoneRules.java

示例5: findYear

import java.time.ZoneOffset; //导入方法依赖的package包/类
private int findYear(long epochSecond, ZoneOffset offset) {
    // inline for performance
    long localSecond = epochSecond + offset.getTotalSeconds();
    long localEpochDay = Math.floorDiv(localSecond, 86400);
    return LocalDate.ofEpochDay(localEpochDay).getYear();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:7,代码来源:ZoneRules.java

示例6: writeRule

import java.time.ZoneOffset; //导入方法依赖的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());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:50,代码来源:ZoneRules.java

示例7: toEpochSecond

import java.time.ZoneOffset; //导入方法依赖的package包/类
/**
 * Converts this date-time to the number of seconds from the epoch
 * of 1970-01-01T00:00:00Z.
 * <p>
 * This combines this local date-time and the specified offset to calculate the
 * epoch-second value, which is the number of elapsed seconds from 1970-01-01T00:00:00Z.
 * Instants on the time-line after the epoch are positive, earlier are negative.
 * <p>
 * This default implementation calculates from the epoch-day of the date and the
 * second-of-day of the time.
 *
 * @param offset  the offset to use for the conversion, not null
 * @return the number of seconds from the epoch of 1970-01-01T00:00:00Z
 */
default long toEpochSecond(ZoneOffset offset) {
    Objects.requireNonNull(offset, "offset");
    long epochDay = toLocalDate().toEpochDay();
    long secs = epochDay * 86400 + toLocalTime().toSecondOfDay();
    secs -= offset.getTotalSeconds();
    return secs;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:ChronoLocalDateTime.java


注:本文中的java.time.ZoneOffset.getTotalSeconds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。