Vimesh Pk Vimesh Pk -4 years ago 179
Android Question

how to convert the json string date to Date format in android

{

"time_slots": [
{
"id": 1,
"from_time": "2000-01-01T09:00:00.000Z",
"to_time": "2000-01-01T10:00:00.000Z",
"created_at": "2016-05-27T08:09:05.979Z",
"updated_at": "2016-05-27T08:09:05.979Z",
"status": true
},
{
"id": 2,
"from_time": "2000-01-01T10:00:00.000Z",
"to_time": "2000-01-01T11:00:00.000Z",
"created_at": "2016-05-27T08:17:43.121Z",
"updated_at": "2016-05-27T08:17:43.121Z",
"status": true
},
{
"id": 3,
"from_time": "2000-01-01T13:00:00.000Z",
"to_time": "2000-01-01T14:00:00.000Z",
"created_at": "2016-05-27T08:18:06.251Z",
"updated_at": "2016-05-27T08:18:06.251Z",
"status": true
},
{
"id": 4,
"from_time": "2000-01-01T14:00:00.000Z",
"to_time": "2000-01-01T15:00:00.000Z",
"created_at": "2016-05-27T08:18:34.752Z",
"updated_at": "2016-05-27T08:18:34.752Z",
"status": true
}


]
}
can any one please help how to convert json string time to Time format in android.I tried to convert using simple date format SimpleDateFormat("yyyy-mm-ddTh:m:s"); but its not working.Any help is really appreciated.

Answer Source

Try this.

SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSS'Z'");
Date myDate = myFormat.parse("your date string here");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download