I have this method:
public Date parseDate(String dateStr) {
try {
SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z");
return sdfSource.parse(dateStr);
}
catch(Exception e) {
throw new RuntimeException("Error occurred while parsing date: " + dateStr);
}
}
And my unit test as below:
public void testEDTDate() throws Exception {
DateFormatConverter converter = new DateFormatConverter();
Date date = converter.parseDate("2009-09-15 15:28:20.0 EDT");
System.out.println("Converted Date: " + date.toString());
}
The output is:
Wed Sep 16 02:28:20 ICT 2009
This cause to the unit test fail. The expected result is:
Tue Sep 15 15:28:20.0 EDT 2009
The format of output also wrong when it missing the second. How should I fix to display the Date as expected?