當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。