AND4011002849 AND4011002849 - 1 year ago 102
Java Question

Format parse exception “EEE MMM dd HH:mm:ss Z yyyy”

My date string is: "Wed Oct 19 14:34:26 BRST 2016" and I'm trying to parse it to "dd/MM/yyyy", but I'm getting the following exception:

java.text.ParseException: Unparseable date: "Wed Oct 19 14:34:26 BRST 2016" (at offset 20)

the method

public String dataText(int lastintervalo) {

Date mDate = new Date();
String dt = mDate.toString();
SimpleDateFormat sdf = new SimpleDateFormat("EE MMM dd HH:mm:ss z yyyy",
Calendar c = Calendar.getInstance();
try {

} catch (ParseException e) {

c.add(Calendar.DATE, lastintervalo);
return sdf.format(c.getTime());


I already searched on google and stackoverflow questions, but nothing seems to work

Answer Source

Since the error message is complaining about offset 20, which is the BRST value, it seems that it cannot resolve the time zone.

Please try this code, that should ensure that the Brazilian time zone is recognized:

SimpleDateFormat sdf = new SimpleDateFormat("EE MMM dd HH:mm:ss z yyyy", Locale.US);
System.out.println(sdf.parse("Wed Oct 19 14:34:26 BRST 2016"));

Since I'm in Eastern US, that prints this for me:

Wed Oct 19 12:34:26 EDT 2016
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download