Dan*_*ite 11 java android json
我正在学习Java并编写一个Android应用程序,它使用服务器传递的JSON对象.
除了约会之外,我一切都在工作.
我得到了其中一个
'SomeKey':'\/Date(1263798000000)\/'
Run Code Online (Sandbox Code Playgroud)
我在用org.json.JSONObject.
我如何转换SomeKey成java.Util.Date?
Eya*_*yal 14
这可能有所帮助:
public static Date JsonDateToDate(String jsonDate)
{
// "/Date(1321867151710)/"
int idx1 = jsonDate.indexOf("(");
int idx2 = jsonDate.indexOf(")");
String s = jsonDate.substring(idx1+1, idx2);
long l = Long.valueOf(s);
return new Date(l);
}
Run Code Online (Sandbox Code Playgroud)
日期格式在JSON中不是标准格式,因此您需要选择"如何通过".我认为你看到的价值是毫克.
在Java中:
System.out.println (new Date(1263798000000L));
// prints: Mon Jan 18 09:00:00 IST 2010
Run Code Online (Sandbox Code Playgroud)
当然,这是我的时区,但无论如何,这是一个相当近的日期.
从Date构造函数的javadoc:
参数:
date - 自1970年1月1日00:00:00 GMT以来的毫秒数.
链接到这里的文档 - > http://java.sun.com/javase/6/docs/api/java/util/Date.html#Date%28long%29
| 归档时间: |
|
| 查看次数: |
15070 次 |
| 最近记录: |