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


Java OffsetDateTime.plusDays方法代码示例

本文整理汇总了Java中java.time.OffsetDateTime.plusDays方法的典型用法代码示例。如果您正苦于以下问题:Java OffsetDateTime.plusDays方法的具体用法?Java OffsetDateTime.plusDays怎么用?Java OffsetDateTime.plusDays使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.OffsetDateTime的用法示例。


在下文中一共展示了OffsetDateTime.plusDays方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doTest_factory_ofInstant_all

import java.time.OffsetDateTime; //导入方法依赖的package包/类
private void doTest_factory_ofInstant_all(long minYear, long maxYear) {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int minOffset = (minYear <= 0 ? 0 : 3);
    int maxOffset = (maxYear <= 0 ? 0 : 3);
    long minDays = (minYear * 365L + ((minYear + minOffset) / 4L - (minYear + minOffset) / 100L + (minYear + minOffset) / 400L)) - days_0000_to_1970;
    long maxDays = (maxYear * 365L + ((maxYear + maxOffset) / 4L - (maxYear + maxOffset) / 100L + (maxYear + maxOffset) / 400L)) + 365L - days_0000_to_1970;

    final LocalDate maxDate = LocalDate.of(Year.MAX_VALUE, 12, 31);
    OffsetDateTime expected = OffsetDateTime.of(LocalDate.of((int) minYear, 1, 1), LocalTime.of(0, 0, 0, 0), ZoneOffset.UTC);
    for (long i = minDays; i < maxDays; i++) {
        Instant instant = Instant.ofEpochSecond(i * 24L * 60L * 60L);
        try {
            OffsetDateTime test = OffsetDateTime.ofInstant(instant, ZoneOffset.UTC);
            assertEquals(test, expected);
            if (expected.toLocalDate().equals(maxDate) == false) {
                expected = expected.plusDays(1);
            }
        } catch (RuntimeException|Error ex) {
            System.out.println("Error: " + i + " " + expected);
            throw ex;
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:TestOffsetDateTime_instants.java

示例2: factory_ofInstant_allDaysInCycle

import java.time.OffsetDateTime; //导入方法依赖的package包/类
public void factory_ofInstant_allDaysInCycle() {
    // sanity check using different algorithm
    OffsetDateTime expected = OffsetDateTime.of(LocalDate.of(1970, 1, 1), LocalTime.of(0, 0, 0, 0), ZoneOffset.UTC);
    for (long i = 0; i < 146097; i++) {
        Instant instant = Instant.ofEpochSecond(i * 24L * 60L * 60L);
        OffsetDateTime test = OffsetDateTime.ofInstant(instant, ZoneOffset.UTC);
        assertEquals(test, expected);
        expected = expected.plusDays(1);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:TestOffsetDateTime_instants.java

示例3: test_plusDays

import java.time.OffsetDateTime; //导入方法依赖的package包/类
@Test
public void test_plusDays() {
    OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
    OffsetDateTime test = base.plusDays(1);
    assertEquals(test, OffsetDateTime.of(2008, 7, 1, 11, 30, 59, 0, OFFSET_PONE));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:TCKOffsetDateTime.java

示例4: test_plusDays_zero

import java.time.OffsetDateTime; //导入方法依赖的package包/类
@Test
public void test_plusDays_zero() {
    OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
    OffsetDateTime test = base.plusDays(0);
    assertSame(test, base);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:TestOffsetDateTime.java


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