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,627
  • 27
  • 97
  • 160
  • 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
  • 130,641
  • 51
  • 193
  • 212
1

There is a T in your source String:

"2012-08-02<b>T</b>00:00:00"
Blackbelt
  • 152,872
  • 27
  • 286
  • 297
bitrevolution
  • 407
  • 5
  • 15
1

Change the format to

yyyy-MM-dd'T'HH:mm:ss
bluish
  • 24,718
  • 26
  • 114
  • 174
jmj
  • 232,312
  • 42
  • 391
  • 431