本文整理汇总了Java中java.time.Year.with方法的典型用法代码示例。如果您正苦于以下问题:Java Year.with方法的具体用法?Java Year.with怎么用?Java Year.with使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.Year
的用法示例。
在下文中一共展示了Year.with方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_with
import java.time.Year; //导入方法依赖的package包/类
@Test
public void test_with() {
Year base = Year.of(5);
Year result = base.with(ChronoField.ERA, 0);
assertEquals(result, base.with(IsoEra.of(0)));
int prolepticYear = IsoChronology.INSTANCE.prolepticYear(IsoEra.of(0), 5);
assertEquals(result.get(ChronoField.ERA), 0);
assertEquals(result.get(ChronoField.YEAR), prolepticYear);
assertEquals(result.get(ChronoField.YEAR_OF_ERA), 5);
result = base.with(ChronoField.YEAR, 10);
assertEquals(result.get(ChronoField.ERA), base.get(ChronoField.ERA));
assertEquals(result.get(ChronoField.YEAR), 10);
assertEquals(result.get(ChronoField.YEAR_OF_ERA), 10);
result = base.with(ChronoField.YEAR_OF_ERA, 20);
assertEquals(result.get(ChronoField.ERA), base.get(ChronoField.ERA));
assertEquals(result.get(ChronoField.YEAR), 20);
assertEquals(result.get(ChronoField.YEAR_OF_ERA), 20);
}
示例2: test_with_TemporalAdjuster
import java.time.Year; //导入方法依赖的package包/类
@Test
public void test_with_TemporalAdjuster() {
Year base = Year.of(-10);
for (int i = -4; i <= 2104; i++) {
Temporal result = base.with(Year.of(i));
assertEquals(result, Year.of(i));
}
}
示例3: test_with_BadTemporalAdjuster
import java.time.Year; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeException.class)
public void test_with_BadTemporalAdjuster() {
Year test = Year.of(1);
test.with(LocalTime.of(18, 1, 2));
}