0

I have used this code to parse a String received from Json in Date Format.

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                try{
                                    Date myDateConference = sdf.parse(jsonO.getString("myDateConference")); 
                                }
                                catch(ParseException e){
                                    e.printStackTrace();
                                }

The String of the date is something in this form 2012-08-02T00:00:00

But I get this exception

java.text.ParseException: Unparseable date: "2012-08-02T00:00:00"

What is wrong?

AndreaF
  • 11,975
  • 27
  • 102
  • 168
  • already answered here: http://stackoverflow.com/questions/2597083/illegal-pattern-character-t-when-parsing-a-date-string-to-java-date?rq=1 – qedejavu Jul 16 '12 at 09:37

3 Answers3

4

use

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

instead of

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
1

There is a T in your source String:

"2012-08-02<b>T</b>00:00:00"
Blackbelt
  • 156,034
  • 29
  • 297
  • 305
bitrevolution
  • 437
  • 6
  • 16
1

Change the format to

yyyy-MM-dd'T'HH:mm:ss
bluish
  • 26,356
  • 27
  • 122
  • 180
jmj
  • 237,923
  • 42
  • 401
  • 438