AndreaF
AndreaF

Reputation: 12395

Cannot parse String into Date from Json, UnparsableDateException

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?

Upvotes: 0

Views: 1586

Answers (3)

Jigar Joshi
Jigar Joshi

Reputation: 240928

Change the format to

yyyy-MM-dd'T'HH:mm:ss

Upvotes: 1

bitrevolution
bitrevolution

Reputation: 467

There is a T in your source String:

"2012-08-02<b>T</b>00:00:00"

Upvotes: 1

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132992

use

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

instead of

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

Upvotes: 4

Related Questions