本文整理汇总了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;
}
}
}
示例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);
}
}
示例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));
}
示例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);
}