I have: CreatedTime TIMESTAMP, UpdatedTime TIMESTAMP, Status Varchar, AutoID columns
in mysql. Through my service i got the following json format.
{
"CreatedTime": "\/Date(1457646424000)\/",
"UpdatedTime": "\/Date(1457647761000)\/",
"Status": "Open",
"AutoID": 1
}
I'm trying to convert the CreatedTime and UpdatedTime like below:
public String ConvertJsonDateTime(String jsondate)
{
if (jsondate != "" && !jsondate.equals("") && jsondate != null && jsondate != "null") {
jsondate = jsondate.replace("/Date(", "").replace(")/", "");
long time = Long.parseLong(jsondate);
Date d = new Date(time);
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(d).toString();
} else {
return "";
}
}
But it returns the wrong details. for example in Table the CreatedTime
is 2016-03-10 14:47:04
but the function ConvertJsonDateTime
returns as 2016-03-11 03:17:04
. How can i fix this one?