![](/img/trans.png)
[英]How to convert Date from facebook api into android app date format
[英]How to format the date in this android app
现在在我的Android应用中,“创建”日期的格式为:2014-02-21 00:00:00
我希望它采用以下格式:2014年2月21日00:00:00
如果可以在这段代码中对其进行重新格式化,请有人告诉我如何?
@Override
protected void onPostExecute(String sJson) {
if(sJson == null) {
if(listener != null) listener.onFetchFailure(msg);
return;
}
try {
// convert json string to json array
JSONArray aJson = new JSONArray(sJson);
// create apps list
List<Application> apps = new ArrayList<Application>();
for(int i=0; i<aJson.length(); i++) {
JSONObject json = aJson.getJSONObject(i);
Application app = new Application();
app.setTitle(json.getString("app_title"));
app.setDesc(json.getString("description"));
app.setCreator(json.getString("creator"));
app.setCreated(json.getString("created"));
app.setRank(json.getString("rating"));
app.setIcon(json.getString("icon"));
// add the app to apps list
apps.add(app);
}
//notify the activity that fetch data has been complete
if(listener != null) listener.onFetchComplete(apps);
} catch (JSONException e) {
msg = "Invalid response";
if(listener != null) listener.onFetchFailure(msg);
return;
}
}
请尝试以下操作:
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
SimpleDateFormat sdf1=new SimpleDateFormat("MMM dd yyyy hh:mm:ss");
app.setCreated(sdf1.format(sdf.parse(json.getString("created"))));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.