Search code examples
javaparsingsimpledateformat

Unparsable Date Exception : SimpleDateFormat


am getting date as string

String dateStr = Mon Mar 31 2014 00:00:00 GMT+0530 (India Standard Time) 

but am getting unparsable date exception when am tring to parse using SimpleDateFormat

java.util.Date date = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss Z", Locale.ENGLISH).parse(dateStr);

please help me to solve this


Solution

  • The "GMT" part is confusing things - the Z format specifier expects just "0800" or similar.

    You can change your format to:

    "EEE MMM dd yyyy HH:mm:ss 'GMT'Z"
    

    and that will work. (It's ignoring the time zone name at the end of the string, of course.)