How to parse json object date on Android

How to parse json date, for example \/Date(1391802454790-0700)\/- (01/31/2014 11:44 AM)in Android.

API Result:

{
    "Comment":"ogogog",
    "CommentDate":"\/Date(1391802454790-0700)\/",
    "CommentReply":[
    ],
    "NumberOfLikes":1,   
    "UniqueId":"f786e0da-2e4a-430f-a37c-c60db1901e38",
    "VideoId":65   
}

I tried under the code, but did not display how this format is (01/31/2014 11:44 AM).

String json = "\/Date(1391802454790-0700)\/"; 
//String json = "commentReplyCommentDate";
json=json.replace("/Date(", "").replace("-0700)/", "");
long time = Long.parseLong(json);
Date d= new Date(time);
System.out.println("Dateeee---->"+d);
+3
source share
1 answer

You must format dDate withMM/dd/yyyy hh:mm a

    String json = "/Date(1391802454790-0700)/";
    json=json.replace("/Date(", "").replace("-0700)/", "");
    long time = Long.parseLong(json);
    Date d= new Date(time);
    System.out.println("Dateeee---->"+d);
    System.out.println(new SimpleDateFormat("MM/dd/yyyy hh:mm a").format(d));

Conclusion:

   Dateeee---->Sat Feb 08 01:17:34 IST 2014
   02/08/2014 01:17 AM
0
source

All Articles