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


Java ChronoUnit.valueOf方法代碼示例

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


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

示例1: toIntervalStart

import java.time.temporal.ChronoUnit; //導入方法依賴的package包/類
public ZonedDateTime toIntervalStart(ZonedDateTime time) {
    ZonedDateTime start;
    switch (ChronoUnit.valueOf(unit.toString().toUpperCase())) {
        case SECONDS:
            start = time.truncatedTo(ChronoUnit.MINUTES);
            break;
        case MINUTES:
            start = time.truncatedTo(ChronoUnit.HOURS);
            break;
        case HOURS:
            start = time.truncatedTo(ChronoUnit.DAYS);
            break;
        case DAYS:
            start = time.with(TemporalAdjusters.firstDayOfYear()).truncatedTo(ChronoUnit.DAYS);
            break;
        default:
            start = time.with(TemporalAdjusters.firstDayOfYear()).truncatedTo(ChronoUnit.DAYS);
    }
    long haveMillis = Duration.between(start, time).toMillis();
    long maxMillis = duration.toMillis();
    long periods = haveMillis / maxMillis;
    start = start.plus(duration.multipliedBy(periods));
    return start;
}
 
開發者ID:hylkevds,項目名稱:SensorThingsProcessor,代碼行數:25,代碼來源:ProcessorBatchAggregate.java

示例2: resolveTimestamp

import java.time.temporal.ChronoUnit; //導入方法依賴的package包/類
private Timestamp resolveTimestamp(String timestampState, String timestampUnitString, long amountToAddValue, String amountToAddUnit) {
    ChronoUnit timestampUnit = ChronoUnit.valueOf(timestampUnitString.toUpperCase());
    ZonedDateTime timestamp = truncate(executionInstant.atZone(systemDefault()), timestampUnit);

    if (timestampState.equalsIgnoreCase("past")) {
        timestamp = timestamp.minus(1, timestampUnit);
    } else if (timestampState.equalsIgnoreCase("future")) {
        timestamp = timestamp.plus(1, timestampUnit);
    }

    if (amountToAddValue != 0 && amountToAddUnit != null) {
        timestamp = timestamp.plus(amountToAddValue, ChronoUnit.valueOf(amountToAddUnit.toUpperCase()));
    }

    return new Timestamp(timestamp.toInstant().toEpochMilli());
}
 
開發者ID:StefaniniInspiring,項目名稱:pugtsdb,代碼行數:17,代碼來源:RollUpAggregationSteps.java

示例3: resolveTimestamp

import java.time.temporal.ChronoUnit; //導入方法依賴的package包/類
private Timestamp resolveTimestamp(String timestampState, String timestampUnitString) {
    ChronoUnit timestampUnit = ChronoUnit.valueOf(timestampUnitString.toUpperCase());
    ZonedDateTime timestamp = truncate(executionInstant.atZone(systemDefault()), timestampUnit);

    if (timestampState.equalsIgnoreCase("past")) {
        timestamp = timestamp.minus(1, timestampUnit);
    } else if (timestampState.equalsIgnoreCase("future")) {
        timestamp = timestamp.plus(1, timestampUnit);
    }

    return new Timestamp(timestamp.toInstant().toEpochMilli());
}
 
開發者ID:StefaniniInspiring,項目名稱:pugtsdb,代碼行數:13,代碼來源:RollUpGranularitySteps.java

示例4: resolveTimestamp

import java.time.temporal.ChronoUnit; //導入方法依賴的package包/類
private Timestamp resolveTimestamp(String state, long diff, String unitString) {
    ChronoUnit timestampUnit = ChronoUnit.valueOf(unitString.toUpperCase());
    ZonedDateTime timestamp = truncate(executionInstant.atZone(systemDefault()), timestampUnit);

    if (state.equalsIgnoreCase("past")) {
        timestamp = timestamp.minus(diff, timestampUnit);
    } else if (state.equalsIgnoreCase("future")) {
        timestamp = timestamp.plus(diff, timestampUnit);
    }

    return new Timestamp(timestamp.toInstant().toEpochMilli());
}
 
開發者ID:StefaniniInspiring,項目名稱:pugtsdb,代碼行數:13,代碼來源:RollUpPurgeSteps.java

示例5: before

import java.time.temporal.ChronoUnit; //導入方法依賴的package包/類
@Given("^I have a published publication with nominal date falling before (-?\\d+) (days|weeks|years) from now$")
public void iHaveAPublishedPublicationWithNominalDateFallingBeforeWeeksFromNow(final int valueFromNow, final String unit)
    throws Throwable {

    ChronoUnit chronoUnit = ChronoUnit.valueOf(unit.toUpperCase());
    final Publication publicationWithNominalDateBeforeCutOff = TestDataFactory.createBareMinimumPublication()
        .withNominalDate(LocalDateTime.now()
            .plus(valueFromNow, chronoUnit)
            .toInstant(ZoneOffset.UTC))
        .build();

    testDataRepo.setPublication(publicationWithNominalDateBeforeCutOff);

    createPublishedPublication(publicationWithNominalDateBeforeCutOff);
}
 
開發者ID:NHS-digital-website,項目名稱:hippo,代碼行數:16,代碼來源:CmsSteps.java

示例6: granularityOf

import java.time.temporal.ChronoUnit; //導入方法依賴的package包/類
private Granularity granularityOf(long granularityValue, String granularityUnit) {
    ChronoUnit unit = ChronoUnit.valueOf(granularityUnit.toUpperCase());
    return unit == ChronoUnit.MILLIS ? null : Granularity.valueOf(granularityValue, unit);
}
 
開發者ID:StefaniniInspiring,項目名稱:pugtsdb,代碼行數:5,代碼來源:RollUpListenerSteps.java


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