-1
我在我的表中設置了一個列數據類型爲CURRENT_TIMESTAMP。它成功保存了當前時間。在Android中從mysql解析日期
2016-06-28 11:00:44 // it's actual mysql data
但是,當我使用的Android GSON解析它,我得到的日期字符串像
2016-06-28T06:09:54.000Z // parsed from json
這意味着空間被改變爲T &ž。我如何刪除這兩個領域?
我的分析數據是像
Gson gson = new Gson();
String json = gson.toJson(args);
JSONArray test = new JSONArray(json);
Log.i("user registration", json);
//JSONArray jsonArray = new JSONArray(args);
//String aa = jsonArray.getString(0).toString();
//String aa = jsonArray.getString(0).toString();
// Log.i("user registration", aa);
String aa = test.getString(0).toString();
JSONObject jsonObject = test.getJSONObject(0);
JSONArray valueArrays = jsonObject.getJSONArray("values");
// // // // Log.e("email",newArr.getJSONObject(0).getString("email"));
for (int i = 0; i < valueArrays.length(); i++) {
JSONObject jo = valueArrays.getJSONObject(i);
String nvp = jo.getString("nameValuePairs");
jo = new JSONObject(nvp);
User user = new User();
String name = jo.getString("user_name");
user.setUserName(name);
if (name.equalsIgnoreCase(mUsername)) {
Log.i("user_matched", "I am " + mUsername);
continue;
}
user.setEmail(jo.getString("email"));
user.setSocket_id(jo.getString("socket_id"));
user.setLastSeen(jo.getString("last_seen"));
if (jo.getString("status") == "1") {
user.setStatus("online");
} else
user.setStatus("offline");
mUserList.add(user);
}
在這裏發表您的代碼.. – Ironman
https://en.wikipedia.org/wiki/ISO_8601 – Selvin
試試這個'SimpleDateFormat sdf = new SimpleDateFormat(「yyyy-MM-dd'T'hh:mm:ss.SSS'Z'」)''。並用這個simpledateformat obj'sdf'解析你的日期 – SripadRaj