I am using Volley
to get the data from Api.I am receiving Time and date in this format 2018-04-04T08:41:21.265185Z
.I want to set time as Local time in RecyclerView
in this format 8:41 PM
.
This is code for converting the Time
SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
dateFormat.setTimeZone(TimeZone.getDefault());
try {
Date date=dateFormat.parse(bookingTime);
TimeZone zone=TimeZone.getDefault();
dateFormat.setTimeZone(zone);
finalTime=dateFormat.format(date);
} catch (ParseException e) {
e.printStackTrace();
}
This is code for setting the converted time to ReyclerView
JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, url, null, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
try {
for (int i = 0; i < response.length(); i++) {
JSONObject object = response.getJSONObject(i);
final CurrentEntry entry = new CurrentEntry();
String id = object.getString("myid");
String Time=object.getString("time");
SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
dateFormat.setTimeZone(TimeZone.getDefault());
try {
Date date=dateFormat.parse(Time);
TimeZone zone=TimeZone.getDefault();
dateFormat.setTimeZone(zone);
finalTime=dateFormat.format(date);
} catch (ParseException e) {
e.printStackTrace();
}
JsonObjectRequest foodie_request = new JsonObjectRequest(Request.Method.GET, myurl, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
String fname = response.getString("fname");
String lname = response.getString("lname");
entry.setName(first_name + "\t" + last_name);
// progressDialog.dismiss();
adapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
})
};
AppController.getInstance().addToRequestQueue(foodie_request, foodie_data_req);
String no = object.getString("no");
String ptime = object.getString("pt");
entry.setP(people);
entry.setT(finalTime);
current.add(entry);
adapter = new CurrentStatusAdapter(current, getActivity().getApplicationContext());
recyclerView.setAdapter(adapter);
}
How to convert and set this time ?