1

I am receiving the string in this format "2014-02-09T00:00:00+05:30" then how can i convert into java.util.date object.

final String ISO_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS zzz";
dateInString="2014-02-09T00:00:00+05:30";       
final SimpleDateFormat sdf = new SimpleDateFormat(ISO_FORMAT);
final TimeZone utc =TimeZone.getTimeZone("GMT");
Date date = formatter.parse(dateInString);
System.out.println(date);

I have tried this way.Its giving java.text.ParseException:

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
Chaitu
  • 79
  • 1
  • 6

2 Answers2

1

try this format "yyyy-MM-dd'T'HH:mm:ssXXX" for more information Class SimpleDateFormat

snvrthn
  • 385
  • 1
  • 10
0

Your format is wrong, I think your looking for yyyy-MM-dd'T'HH:mm:ssXXX. S is for millisecondes, you don't need this.

Note that XXX will work with Java 7 (see documentation : http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html), it's the ISO 8601 time zone format.

With Java 6 you can only use ZZZ but it won't match +05:30 because ZZZ match RFC 822 time zone format

If you're using Java 6, please refer to this answer : https://stackoverflow.com/a/2202300/1140748

Community
  • 1
  • 1
alain.janinm
  • 19,951
  • 10
  • 65
  • 112