本文整理汇总了Java中java.time.Instant.atZone方法的典型用法代码示例。如果您正苦于以下问题:Java Instant.atZone方法的具体用法?Java Instant.atZone怎么用?Java Instant.atZone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.Instant
的用法示例。
在下文中一共展示了Instant.atZone方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculateIntervalsForTime
import java.time.Instant; //导入方法依赖的package包/类
public List<Interval> calculateIntervalsForTime(TimeObject phenTime) {
List<Interval> retval = new ArrayList<>();
Instant phenTimeStart = getPhenTimeStart(phenTime);
Instant phenTimeEnd = getPhenTimeEnd(phenTime);
ZonedDateTime atZone = phenTimeStart.atZone(getZoneId());
ZonedDateTime intStart = level.toIntervalStart(atZone);
ZonedDateTime intEnd = intStart.plus(level.amount, level.unit);
retval.add(Interval.of(intStart.toInstant(), intEnd.toInstant()));
while (intEnd.toInstant().isBefore(phenTimeEnd)) {
intStart = intEnd;
intEnd = intStart.plus(level.amount, level.unit);
retval.add(Interval.of(intStart.toInstant(), intEnd.toInstant()));
}
return retval;
}
示例2: parseUTCTime
import java.time.Instant; //导入方法依赖的package包/类
/**
* Parses string as time
* accepted formats are milliseconds from epoch and valid date string
*
* @throws DateTimeParseException if the value cannot be parsed as valid datetime
*/
public static ZonedDateTime parseUTCTime(String value) {
try {
// parses ms unix time and returns at UTC offset
Instant instant = Instant.ofEpochMilli(Long.parseLong(value));
return instant.atZone(ZoneOffset.UTC);
} catch (NumberFormatException e) {
// parse passed date
return Optional.of(ZonedDateTime.parse(value))
// convert to UTC
.map(zdt -> zdt.withZoneSameInstant(ZoneOffset.UTC))
// and return the value; this is safe to call without orElse,
// since ZonedDateTime will throw an exception if it cannot parse the value
.get();
}
}
示例3: instantOfNextFrame
import java.time.Instant; //导入方法依赖的package包/类
@Override
public Instant instantOfNextFrame(final Instant instant) {
final ZonedDateTime britishTime = instant.atZone(BRITISH_TIME_ZONE);
final DayOfWeek britishDay = britishTime.getDayOfWeek();
if (britishDay != SUNDAY) {
return removeMinutesAndLess(britishTime).withHour(0).plus(1, DAYS).toInstant();
}
final ZonedDateTime britishTimeCorrectTimeValues = removeMinutesAndLess(britishTime).withHour(22);
if (britishTime.getDayOfWeek() == SUNDAY) {
if (britishTime.isBefore(britishTimeCorrectTimeValues)) {
return britishTimeCorrectTimeValues.toInstant();
}
return removeMinutesAndLess(britishTime).withHour(0).plus(2, DAYS).toInstant();
}
return britishTimeCorrectTimeValues.with(TemporalAdjusters.next(SUNDAY)).toInstant();
}
示例4: test_atZone
import java.time.Instant; //导入方法依赖的package包/类
@Test
public void test_atZone() {
for (int i = 0; i < (24 * 60 * 60); i++) {
Instant instant = Instant.ofEpochSecond(i);
ZonedDateTime test = instant.atZone(ZoneOffset.ofHours(1));
assertEquals(test.getYear(), 1970);
assertEquals(test.getMonthValue(), 1);
assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0));
assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24);
assertEquals(test.getMinute(), (i / 60) % 60);
assertEquals(test.getSecond(), i % 60);
}
}
示例5: areInSameTimeFrame
import java.time.Instant; //导入方法依赖的package包/类
@Override
public boolean areInSameTimeFrame(final Instant instant1, final Instant instant2) {
final ZonedDateTime britishTime = instant1.atZone(BRITISH_TIME_ZONE);
final DayOfWeek britishDay = britishTime.getDayOfWeek();
final ZonedDateTime localBase = britishTime.withHour(0).withMinute(0).withSecond(0).withNano(0);
final ZonedDateTime start;
final ZonedDateTime end;
if (britishDay == SUNDAY) {
if (britishTime.isBefore(localBase.withHour(22))) {
start = localBase;
end = localBase.withHour(22);
} else {
start = localBase.withHour(22);
end = localBase.plusDays(2);
}
} else if (britishDay == MONDAY) {
start = localBase.minusDays(1).withHour(22);
end = localBase.plusDays(1);
} else {
start = localBase;
end = localBase.plusDays(1);
}
return instant2.equals(start.toInstant())
|| (instant2.isAfter(start.toInstant()) && instant2.isBefore(end.toInstant()));
}
示例6: calculateAggregates
import java.time.Instant; //导入方法依赖的package包/类
private void calculateAggregates(AggregateCombo combo) throws ServiceFailureException, ProcessException {
Observation lastAggObs = combo.getLastForTarget();
Instant calcIntervalStart;
if (lastAggObs == null) {
Observation firstSourceObs = combo.getFirstForSource();
if (firstSourceObs == null) {
LOGGER.debug("No source observations at all for {}.", combo);
return;
}
Instant firstSourceStart = getPhenTimeStart(firstSourceObs);
ZonedDateTime atZone = firstSourceStart.atZone(combo.getZoneId());
ZonedDateTime firstIntStart = combo.level.toIntervalStart(atZone);
if (atZone.isEqual(firstIntStart)) {
calcIntervalStart = firstIntStart.toInstant();
} else {
calcIntervalStart = firstIntStart.plus(combo.level.duration).toInstant();
}
} else {
TimeObject lastAggPhenTime = lastAggObs.getPhenomenonTime();
calcIntervalStart = lastAggPhenTime.getAsInterval().getEnd();
}
Observation lastSourceObs = combo.getLastForSource();
if (lastSourceObs == null) {
LOGGER.debug("No source observations at all for {}.", combo);
return;
}
Instant lastSourcePhenTime = getPhenTimeEnd(lastSourceObs);
boolean more = true;
while (more) {
Instant calcIntervalEnd = calcIntervalStart.plus(combo.level.duration);
if (lastSourcePhenTime.isBefore(calcIntervalEnd)) {
LOGGER.info("Nothing (more) to do for {}.", combo);
return;
}
calculateAggregate(combo, Interval.of(calcIntervalStart, calcIntervalEnd));
calcIntervalStart = calcIntervalEnd;
}
}
示例7: fromDateForUTC
import java.time.Instant; //导入方法依赖的package包/类
public static ZonedDateTime fromDateForUTC(Date date) {
Instant instant = date.toInstant();
return instant.atZone(ZONE_UTC);
}