0

Hi folks I am trying to parse this format but not able to it .

Format : Fri Oct 21 2011 08:45:00 GMT 0530 (IST)

SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss zzz ZZZZ")

Can some one explain me what is wrong in this ?

2
  • 3
    That 0530 has to be in RFC 822 format +0530 in order to get it parsed as such. You can't parse it without manipulating the string beforehand.
    – BalusC
    Oct 21, 2011 at 5:21
  • I did change it to +0530 but still I am not able to parse it Fri Oct 21 2011 08:00:00 GMT+0530 (IST) new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss z (Z)")
    – user437066
    Oct 21, 2011 at 6:05

1 Answer 1

5

The format for your zzz is incorrect; the docs show that it needs to be in this format: GMT-05:30.

Also, since you have parentheses around the Z parameter, you need parentheses in your format string.

sdf = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss z (Z)")
println sdf.parse("Fri Oct 21 2011 08:45:00 GMT+05:30 (IST)")
> Fri Oct 21 02:45:00 EDT 2011
2
  • Problem is I am getting this as input from a api Fri Oct 21 2011 08:00:00 GMT 0530 (IST) and I cannot change the input
    – user437066
    Oct 21, 2011 at 5:49
  • @user437066 But you have a string, and you can modify that :) Oct 21, 2011 at 6:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.