當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。