我试图使用LocalDateTime从html页面解析日期。而且我无法提出解决方案来进行以下测试。
(使用TestNG)第一行总是失败
static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("E MMM dd HH:mm:ss u");
@DataProvider(name = "dateTimeFormats")
public Object[][] dateTimeFormats() {
return new Object[][]{
{"Mon Jan 5 06:41:07 2015", LocalDateTime.of(2015, 1, 5, 6, 41, 7)},
{"Sun Jan 25 00:48:23 2015", LocalDateTime.of(2015, 1, 25, 0, 48, 23)},
{"Mon Aug 14 07:58:00 2006", LocalDateTime.of(2006, 8, 14, 7, 58, 0)}
};
}
@Test(dataProvider = "dateTimeFormats")
public void testParsePostDateTime(String dateTimeString, LocalDateTime expectedResult) {
LocalDateTime result = LocalDateTime.parse(dateTimeString, DATE_TIME_FORMATTER);
assertEquals(result, expectedResult);
}
应该使用哪种日期模式的想法?