當前位置: 首頁>>代碼示例>>Java>>正文


Java Instant.truncatedTo方法代碼示例

本文整理匯總了Java中java.time.Instant.truncatedTo方法的典型用法代碼示例。如果您正苦於以下問題:Java Instant.truncatedTo方法的具體用法?Java Instant.truncatedTo怎麽用?Java Instant.truncatedTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.Instant的用法示例。


在下文中一共展示了Instant.truncatedTo方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: rollIfNeeded

import java.time.Instant; //導入方法依賴的package包/類
/**
 * If necessary, close the current logfile and open a new one,
 * updating {@link #writer}.
 */
private void rollIfNeeded() throws IOException {
    // Do not roll unless record is complete, as indicated by flush
    if (!flushed) return;
    flushed = false;

    // If we have not yet passed the roll over mark do nothing
    Instant now = Instant.now();
    if (now.isBefore(rollAt)) {
        return;
    }

    // New file time, may not be the rollAt time if one or more intervals
    // have passed without anything being written
    Instant rollTime = now.truncatedTo(rollInterval);

    // Determine the name of the file that will be written to
    String name = this.baseName + format.format(LocalDateTime.ofInstant(rollTime, timeZone));
    this.outPath = this.directory.resolve(name);

    // Finish writing to previous log
    if (writer != null) {
        writer.flush();
        writer.close();
    }

    // Ensure the parent directory always exists, even if it was removed out from under us.
    // A no-op if the directory already exists.
    Files.createDirectories(outPath.getParent());

    // Create new file, set it as our write destination
    writer = Files.newBufferedWriter(
                outPath,
                StandardCharsets.UTF_8,
                StandardOpenOption.CREATE,
                StandardOpenOption.APPEND);

    // Point to the next time we want to roll the log, update rollAt
    this.rollAt = rollTime.plus(1, rollInterval);
}
 
開發者ID:awslabs,項目名稱:swage,代碼行數:44,代碼來源:RollingFileWriter.java

示例2: test_truncatedTo_invalid

import java.time.Instant; //導入方法依賴的package包/類
@Test(dataProvider="truncatedToInvalid", expectedExceptions=DateTimeException.class)
public void test_truncatedTo_invalid(Instant input, TemporalUnit unit) {
    input.truncatedTo(unit);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:TCKInstant.java

示例3: getDateRange

import java.time.Instant; //導入方法依賴的package包/類
/**
 * Returns the earliest/latest {@link Date} based on the {@link DateValue#getDate()}
 * and {@link DateValue#getGrain()}.
 * @param dateValue the date value
 * @return the earliest possible start in {@link Pair#getLeft()} and the latest
 * possible end in {@link Pair#getRight()}. If the parsed {@link DateValue} does
 * not have a {@link DateValue#getGrain()} the left and right date will be the
 * value of {@link DateValue#getDate()}
 * @throws NullPointerException if the parsed {@link DateValue} or
 * {@link DateValue#getDate()} are <code>null</code>
 */
public static Pair<Date, Date> getDateRange(DateValue dateValue){
    if(dateValue.getGrain() == null){
        return new ImmutablePair<>(dateValue.getDate(), dateValue.getDate());
    } else {
        Instant inst = dateValue.getDate().toInstant();
        Instant startInst = inst.truncatedTo(dateValue.getGrain().getChronoUnit());
        Instant endInst = startInst.plus(1,dateValue.getGrain().getChronoUnit());
        return new ImmutablePair<>(Date.from(startInst), Date.from(endInst));
    }
}
 
開發者ID:redlink-gmbh,項目名稱:smarti,代碼行數:22,代碼來源:DateUtils.java


注:本文中的java.time.Instant.truncatedTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。