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