1

I've a date = 2011-04-17T22:02:00.001-07:00 that I'm parsing using SDF

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
formatter.parse(date)

I It doesnt support -07:00 but -0700 works. What should change in the format?

Taranfx
  • 10,361
  • 17
  • 77
  • 95
  • Try using [TimeZone](http://download.oracle.com/javase/6/docs/api/java/util/TimeZone.html) it might help you. – Harry Joy Apr 18 '11 at 05:31

2 Answers2

2

It appears that SimpleDateFormat doesn't support ISO8601 time zone formats. If you know for certain that your time zone will always end in the format of -##:## (or +##:##) then you could just remove the last : so that your existing formatter works. E.g. this parses your date:

String input = "2011-04-17T22:02:00.001-07:00";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Date date = sdf.parse(input.replaceAll(":(..)$", "$1"));

Be careful however, apparently ISO8601 allows for some variations whereby this wouldn't work.

WhiteFang34
  • 70,765
  • 18
  • 106
  • 111
1

take a look at :

Converting ISO 8601-compliant String to java.util.Date

it talks about this issue specifically..

Community
  • 1
  • 1
Majed
  • 917
  • 6
  • 18