【发布时间】:2011-05-13 13:09:44
【问题描述】:
我想解析一个日期字符串,但失败得很惨。 为了说明我的问题,我编写了这个简单的 JUnit 测试:
@Test
public void testParseJavaDate() throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD_HH-mm-ss", Locale.GERMAN);
String inputtime = "2011-04-21_16-01-08";
Date parse = sdf.parse(inputtime);
assertEquals(inputtime,sdf.format(parse));
}
此测试失败并显示以下消息:
org.junit.ComparisonFailure: 预期: 但是是:
我不明白为什么格式化程序无法正确解析日期。你有什么想法吗?
【问题讨论】: