本文整理汇总了Java中java.time.format.DateTimeFormatter.withResolverFields方法的典型用法代码示例。如果您正苦于以下问题:Java DateTimeFormatter.withResolverFields方法的具体用法?Java DateTimeFormatter.withResolverFields怎么用?Java DateTimeFormatter.withResolverFields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.format.DateTimeFormatter
的用法示例。
在下文中一共展示了DateTimeFormatter.withResolverFields方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_resolverFields_selectOneDateResolveYD
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test
public void test_resolverFields_selectOneDateResolveYD() throws Exception {
DateTimeFormatter base = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral('-').appendValue(MONTH_OF_YEAR).appendLiteral('-')
.appendValue(DAY_OF_MONTH).appendLiteral('-').appendValue(DAY_OF_YEAR).toFormatter();
DateTimeFormatter f = base.withResolverFields(YEAR, DAY_OF_YEAR);
Set<TemporalField> expected = new HashSet<>(Arrays.asList(YEAR, DAY_OF_YEAR));
// Use set.equals(); testNG comparison of Collections is ordered
assertTrue(f.getResolverFields().equals(expected), "ResolveFields: " + f.getResolverFields());
try {
base.parse("2012-6-30-321", LocalDate::from); // wrong month/day-of-month
fail();
} catch (DateTimeException ex) {
// expected, fails as it produces two different dates
}
LocalDate parsed = f.parse("2012-6-30-321", LocalDate::from); // ignored month/day-of-month
assertEquals(parsed, LocalDate.of(2012, 11, 16));
}
示例2: test_resolverFields_selectOneDateResolveYMD
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test
public void test_resolverFields_selectOneDateResolveYMD() throws Exception {
DateTimeFormatter base = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral('-').appendValue(MONTH_OF_YEAR).appendLiteral('-')
.appendValue(DAY_OF_MONTH).appendLiteral('-').appendValue(DAY_OF_YEAR).toFormatter();
DateTimeFormatter f = base.withResolverFields(YEAR, MONTH_OF_YEAR, DAY_OF_MONTH);
try {
base.parse("2012-6-30-321", LocalDate::from); // wrong day-of-year
fail();
} catch (DateTimeException ex) {
// expected, fails as it produces two different dates
}
LocalDate parsed = f.parse("2012-6-30-321", LocalDate::from); // ignored day-of-year
assertEquals(parsed, LocalDate.of(2012, 6, 30));
}
示例3: test_resolverFields_ignoreCrossCheck
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test
public void test_resolverFields_ignoreCrossCheck() throws Exception {
DateTimeFormatter base = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral('-').appendValue(DAY_OF_YEAR).appendLiteral('-')
.appendValue(DAY_OF_WEEK).toFormatter();
DateTimeFormatter f = base.withResolverFields(YEAR, DAY_OF_YEAR);
try {
base.parse("2012-321-1", LocalDate::from); // wrong day-of-week
fail();
} catch (DateTimeException ex) {
// expected, should fail in cross-check of day-of-week
}
LocalDate parsed = f.parse("2012-321-1", LocalDate::from); // ignored wrong day-of-week
assertEquals(parsed, LocalDate.of(2012, 11, 16));
}
示例4: test_resolverFields_Array_null
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test
public void test_resolverFields_Array_null() throws Exception {
DateTimeFormatter f = DateTimeFormatter.ISO_DATE.withResolverFields(MONTH_OF_YEAR);
assertEquals(f.getResolverFields().size(), 1);
f = f.withResolverFields((TemporalField[]) null);
assertEquals(f.getResolverFields(), null);
}
示例5: test_resolverFields_Set_null
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test
public void test_resolverFields_Set_null() throws Exception {
DateTimeFormatter f = DateTimeFormatter.ISO_DATE.withResolverFields(MONTH_OF_YEAR);
assertEquals(f.getResolverFields().size(), 1);
f = f.withResolverFields((Set<TemporalField>) null);
assertEquals(f.getResolverFields(), null);
}