解析android中的json日期字符串 [英] Parse json date string in android

查看:121
本文介绍了解析android中的json日期字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I get a json string with number of milliseconds after 1970 from the server in my android app.

看起来像这样: \ /日期(1358157378910 + 0100)\ /

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

How can I parse this into a Java calendar object, or just get some date value from it? Should I start with regex and just get the millisecons? The server is .NET.

谢谢

推荐答案

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

The time seems to also have the timezone there so I would do something like this:

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);

这篇关于解析android中的json日期字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆