当前位置: 首页>>代码示例>>Java>>正文


Java ZonedDateTime.toInstant方法代码示例

本文整理汇总了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();
}
 
开发者ID:rbi,项目名称:trading4j,代码行数:18,代码来源:D1.java

示例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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:TCKZoneRules.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKZonedDateTime.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKZonedDateTime.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKZonedDateTime.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:TCKZoneRules.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:TCKZoneRules.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:TCKZoneRules.java

示例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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:TCKZoneRules.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:TCKZoneRules.java

示例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;
    }

}
 
开发者ID:hylkevds,项目名称:SensorThingsProcessor,代码行数:46,代码来源:ProcessorBatchAggregate.java

示例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);
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:19,代码来源:VirtualGrid.java

示例13: getTime

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public Instant getTime() {

    ZonedDateTime time = delegate.getExecDate();

    return time == null ? null : time.toInstant();

}
 
开发者ID:after-the-sunrise,项目名称:cryptotrader,代码行数:9,代码来源:BitflyerExecution.java


注:本文中的java.time.ZonedDateTime.toInstant方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。