转换JSON日期的"毫米DD YYYY"格式 [英] Convert JSON date in the "mm dd yyyy" format
问题描述
在我的应用程序的日期恶魔JSON响应之际,这种类型的:
In my application the Date Fiend JSON response comes as this type:
"CreatedOn": "\/Date(1313572467987+0000)\/"
我想转换这个日期在MM DD YYYY格式。我如何转换呢?
I want to convert this date in the "MM DD YYYY" format. How can I convert this?
推荐答案
在你的JSON响应该日期看起来像一个标准时间戳(毫秒如数量自1970年1月1日)。如果您解析出时间戳是这样的:
That date in your JSON response looks like a standard timestamp (e.g. number of milliseconds since January 1, 1970). If you parse out the timestamp something like:
String timestamp = jsonValue.split("\\(")[1].split("\\+")[0];
Date createdOn = new Date(Long.parseLong(timestamp));
现在你可以使用SimpleDateFormat的格式化日期字符串:
Now you can use SimpleDateFormat to format a date string:
SimpleDateFormat sdf = new SimpleDateFormat("MM dd yyyy");
String formattedDate = sdf.format(createdOn);
这是忽略了时区调整的响应(+0000),你可能还需要分析出这个值,并添加/格式化前。
This is ignoring the timezone adjustment in that response (the '+0000') you might also want to parse out this value and add/remove the hours from your timestamp value before formatting..
这篇关于转换JSON日期的"毫米DD YYYY"格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!