当前位置: 首页>>代码示例>>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;未经允许,请勿转载。