本文整理汇总了Java中java.time.ZonedDateTime.toInstant方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.toInstant方法的具体用法?Java ZonedDateTime.toInstant怎么用?Java ZonedDateTime.toInstant使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.ZonedDateTime
的用法示例。
在下文中一共展示了ZonedDateTime.toInstant方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: instantOfNextFrame
import java.time.ZonedDateTime; //导入方法依赖的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();
}
示例2: test_Paris_getStandardOffset
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public void test_Paris_getStandardOffset() {
ZoneRules test = europeParis();
ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC);
while (zdt.getYear() < 2010) {
Instant instant = zdt.toInstant();
if (zdt.toLocalDate().isBefore(LocalDate.of(1911, 3, 11))) {
assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, 9, 21));
} else if (zdt.toLocalDate().isBefore(LocalDate.of(1940, 6, 14))) {
assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
} else if (zdt.toLocalDate().isBefore(LocalDate.of(1944, 8, 25))) {
assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
} else if (zdt.toLocalDate().isBefore(LocalDate.of(1945, 9, 16))) {
assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
} else {
assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
}
zdt = zdt.plusMonths(6);
}
}
示例3: test_toInstant_UTC
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test(dataProvider="toInstant")
public void test_toInstant_UTC(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
ZonedDateTime dt = ldt.atZone(ZoneOffset.UTC);
Instant test = dt.toInstant();
assertEquals(test.getEpochSecond(), expectedEpSec);
assertEquals(test.getNano(), expectedNos);
}
示例4: test_toInstant_P0100
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test(dataProvider="toInstant")
public void test_toInstant_P0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
ZonedDateTime dt = ldt.atZone(ZONE_0100);
Instant test = dt.toInstant();
assertEquals(test.getEpochSecond(), expectedEpSec - 3600);
assertEquals(test.getNano(), expectedNos);
}
示例5: test_toInstant_M0100
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test(dataProvider="toInstant")
public void test_toInstant_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
ZonedDateTime dt = ldt.atZone(ZONE_M0100);
Instant test = dt.toInstant();
assertEquals(test.getEpochSecond(), expectedEpSec + 3600);
assertEquals(test.getNano(), expectedNos);
}
示例6: test_London_preTimeZones
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public void test_London_preTimeZones() {
ZoneRules test = europeLondon();
ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
Instant instant = old.toInstant();
ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(0, -1, -15);
assertEquals(test.getOffset(instant), offset);
checkOffset(test, old.toLocalDateTime(), offset, 1);
assertEquals(test.getStandardOffset(instant), offset);
assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
assertEquals(test.isDaylightSavings(instant), false);
}
示例7: test_Paris_preTimeZones
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public void test_Paris_preTimeZones() {
ZoneRules test = europeParis();
ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
Instant instant = old.toInstant();
ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(0, 9, 21);
assertEquals(test.getOffset(instant), offset);
checkOffset(test, old.toLocalDateTime(), offset, 1);
assertEquals(test.getStandardOffset(instant), offset);
assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
assertEquals(test.isDaylightSavings(instant), false);
}
示例8: test_NewYork_preTimeZones
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public void test_NewYork_preTimeZones() {
ZoneRules test = americaNewYork();
ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
Instant instant = old.toInstant();
ZoneOffset offset = ZoneOffset.of("-04:56:02");
assertEquals(test.getOffset(instant), offset);
checkOffset(test, old.toLocalDateTime(), offset, 1);
assertEquals(test.getStandardOffset(instant), offset);
assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
assertEquals(test.isDaylightSavings(instant), false);
}
示例9: test_NewYork_getStandardOffset
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public void test_NewYork_getStandardOffset() {
ZoneRules test = americaNewYork();
ZonedDateTime dateTime = createZDT(1860, 1, 1, ZoneOffset.UTC);
while (dateTime.getYear() < 2010) {
Instant instant = dateTime.toInstant();
if (dateTime.toLocalDate().isBefore(LocalDate.of(1883, 11, 18))) {
assertEquals(test.getStandardOffset(instant), ZoneOffset.of("-04:56:02"));
} else {
assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHours(-5));
}
dateTime = dateTime.plusMonths(6);
}
}
示例10: test_London_getStandardOffset
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public void test_London_getStandardOffset() {
ZoneRules test = europeLondon();
ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC);
while (zdt.getYear() < 2010) {
Instant instant = zdt.toInstant();
if (zdt.getYear() < 1848) {
assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, -1, -15));
} else if (zdt.getYear() >= 1969 && zdt.getYear() < 1972) {
assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
} else {
assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
}
zdt = zdt.plusMonths(6);
}
}
示例11: calculateAggregates
import java.time.ZonedDateTime; //导入方法依赖的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;
}
}
示例12: adjustTime
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* Adjusts the given time either rounding it up or down.
*
* @param time
* the time to adjust
* @param roundUp
* the rounding direction
* @param firstDayOfWeek
* the first day of the week (needed for rounding weeks)
* @return the adjusted time
*/
public ZonedDateTime adjustTime(ZonedDateTime time, boolean roundUp,
DayOfWeek firstDayOfWeek) {
Instant instant = time.toInstant();
ZoneId zoneId = time.getZone();
instant = adjustTime(instant, zoneId, roundUp, firstDayOfWeek);
return ZonedDateTime.ofInstant(instant, zoneId);
}
示例13: getTime
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public Instant getTime() {
ZonedDateTime time = delegate.getExecDate();
return time == null ? null : time.toInstant();
}