本文整理汇总了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;
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
示例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);
}