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


Java DateTimeFormatter.parseBest方法代码示例

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


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

示例1: test_parseBest_String_parseError

import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeParseException.class)
public void test_parseBest_String_parseError() throws Exception {
    DateTimeFormatter test = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm[XXX]");
    try {
        test.parseBest("2011-06-XX", ZonedDateTime::from, LocalDateTime::from);
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getMessage().contains("could not be parsed"), true);
        assertEquals(ex.getMessage().contains("XX"), true);
        assertEquals(ex.getParsedString(), "2011-06-XX");
        assertEquals(ex.getErrorIndex(), 8);
        throw ex;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:TCKDateTimeFormatter.java

示例2: test_parseBest_firstOption

import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test
public void test_parseBest_firstOption() throws Exception {
    DateTimeFormatter test = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm[XXX]");
    TemporalAccessor result = test.parseBest("2011-06-30 12:30+03:00", ZonedDateTime::from, LocalDateTime::from);
    LocalDateTime ldt = LocalDateTime.of(2011, 6, 30, 12, 30);
    assertEquals(result, ZonedDateTime.of(ldt, ZoneOffset.ofHours(3)));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKDateTimeFormatter.java

示例3: test_parseBest_String_parseErrorLongText

import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeParseException.class)
public void test_parseBest_String_parseErrorLongText() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    try {
        test.parseBest("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789", ZonedDateTime::from, LocalDate::from);
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getMessage().contains("could not be parsed"), true);
        assertEquals(ex.getMessage().contains("ONEXXX6789012345678901234567890123456789012345678901234567890123..."), true);
        assertEquals(ex.getParsedString(), "ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
        assertEquals(ex.getErrorIndex(), 3);
        throw ex;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:TCKDateTimeFormatter.java

示例4: test_parseBest_String_parseIncomplete

import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeParseException.class)
public void test_parseBest_String_parseIncomplete() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    try {
        test.parseBest("ONE30SomethingElse", ZonedDateTime::from, LocalDate::from);
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getMessage().contains("could not be parsed"), true);
        assertEquals(ex.getMessage().contains("ONE30SomethingElse"), true);
        assertEquals(ex.getParsedString(), "ONE30SomethingElse");
        assertEquals(ex.getErrorIndex(), 5);
        throw ex;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:TCKDateTimeFormatter.java

示例5: test_parseBest_secondOption

import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test
public void test_parseBest_secondOption() throws Exception {
    DateTimeFormatter test = DateTimeFormatter.ofPattern("yyyy-MM-dd[ HH:mm[XXX]]");
    TemporalAccessor result = test.parseBest("2011-06-30", ZonedDateTime::from, LocalDate::from);
    assertEquals(result, LocalDate.of(2011, 6, 30));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:TCKDateTimeFormatter.java

示例6: test_parseBest_String_nullText

import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void test_parseBest_String_nullText() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    test.parseBest((String) null, ZonedDateTime::from, LocalDate::from);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:TCKDateTimeFormatter.java

示例7: test_parseBest_String_nullRules

import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void test_parseBest_String_nullRules() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    test.parseBest("30", (TemporalQuery<?>[]) null);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:TCKDateTimeFormatter.java

示例8: test_parseBest_String_zeroRules

import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test(expectedExceptions=IllegalArgumentException.class)
public void test_parseBest_String_zeroRules() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    test.parseBest("30", new TemporalQuery<?>[0]);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:TCKDateTimeFormatter.java

示例9: test_parseBest_String_oneRule

import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test(expectedExceptions=IllegalArgumentException.class)
public void test_parseBest_String_oneRule() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    test.parseBest("30", LocalDate::from);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:TCKDateTimeFormatter.java


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