Java 如何将json对象日期解析为Android
如何在Android中解析json日期,如Java 如何将json对象日期解析为Android,java,android,json,datetime,Java,Android,Json,Datetime,如何在Android中解析json日期,如\/date(1391802454790-0700)\/到(01/31/2014 11:44 AM) API结果: { "Comment":"ogogog", "CommentDate":"\/Date(1391802454790-0700)\/", "CommentReply":[ ], "NumberOfLikes":1, "UniqueId":"f786e0da-2e4a-430f-a37c-c
\/date(1391802454790-0700)\/
到(01/31/2014 11:44 AM)
API结果:
{
"Comment":"ogogog",
"CommentDate":"\/Date(1391802454790-0700)\/",
"CommentReply":[
],
"NumberOfLikes":1,
"UniqueId":"f786e0da-2e4a-430f-a37c-c60db1901e38",
"VideoId":65
}
我尝试了下面的代码,但没有以这种格式显示(01/31/2014 11:44 AM)
您应该使用
MM/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));
输出:
Dateeee---->Sat Feb 08 01:17:34 IST 2014
02/08/2014 01:17 AM
我假设日期之前的部分是以毫秒为单位的历元时间,破折号之后是从GMT开始的时区偏移量。把它放到日历对象中,你应该会很好。thanx,我得到了完美的结果。@RuchiraGayanRanaweera不适合我。。错误:说长无效
Dateeee---->Sat Feb 08 01:17:34 IST 2014
02/08/2014 01:17 AM