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


Java DateTimeFormatter.withResolverFields方法代码示例

本文整理汇总了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));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:TCKDateTimeFormatter.java

示例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));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:TCKDateTimeFormatter.java

示例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));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:TCKDateTimeFormatter.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKDateTimeFormatter.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKDateTimeFormatter.java


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