Im trying parse a String with a date to convert it into a Date format. Strings are in the following format.
Wed Mar 30 00:00:00 GMT+05:30 2016
But when im parsing the String i get a error saying,
java.text.ParseException: Unparseable date: "Wed Mar 30 00:00:00 GMT+05:30 2016" (at offset 4)
below is a part of my code. How do i avoid this error? Any help would be appreciated.
SimpleDateFormat sdf3 = new SimpleDateFormat("EEE MM dd kk:mm:ss zzzz yyyy",Locale.ENGLISH);
for(int i=0 ; i <jArr.length() ; i++){
String tempDate = jArr.get(i).toString();
dateList.add(tempDate);
}
try{
Date d1 = sdf3.parse(dateList.get(0));
}catch (Exception e){ e.printStackTrace(); }
MM
,zzzz
? please read the documentation – MonometallismSimpleDateFormat
andDate
. Those classes are poorly designed and long outdated, the former in particular notoriously troublesome. Instead useDateTimeFormatter
and eitherOffsetDateTime
orZonedDateTime
; all three are from java.time, the modern Java date and time API. See the answer by Arvind Kumar Avinash. – Toogood