在android中解析json日期字符串

Pap*_*ick 5 java parsing android json

我在Android应用程序中从服务器获得了1970年以后的毫秒数的json字符串.

看起来像这样:\/Date(1358157378910+0100)\/.

我如何将其解析为Java日历对象,或者只是从中获取一些日期值?我应该从正则表达式开始,只是得到毫秒?服务器是.NET.

谢谢

pab*_*sco 5

时间似乎也有时区,所以我会做这样的事情:

String timeString = json.substring(json.indexOf("(") + 1, json.indexOf(")"));
String[] timeSegments = timeString.split("\\+");
// May have to handle negative timezones
int timeZoneOffSet = Integer.valueOf(timeSegments[1]) * 36000; // (("0100" / 100) * 3600 * 1000)
int millis = Integer.valueOf(timeSegments[0]);
Date time = new Date(millis + timeZoneOffSet);
Run Code Online (Sandbox Code Playgroud)