I can successfully execute the following code snippet in an Android project:
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ssZ", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = null;
try {
date = dateFormat.parse("2015-08-17T19:30:00+02:00");
} catch (ParseException e) {
e.printStackTrace();
}
Now I put the same code snippet into a JUnit4 test:
@RunWith(JUnit4.class)
public class DateUtilsTests {
@Test
public void testFailsWithParseException() {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ssZ", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = null;
try {
date = dateFormat.parse("2015-08-17T19:30:00+02:00");
} catch (ParseException e) {
e.printStackTrace();
}
assertThat(date).isNotEqualTo(null);
}
}
This fails:
java.text.ParseException: Unparseable date: "2015-08-17T19:30:00+02:00"