private void getDate() {
RequestQueue queue = Volley.newRequestQueue(getContext());
String url ="http://worldtimeapi.org/api/timezone/Asia/Kolkata";
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
// stroting datatime in a string
String result = jsonObject.getString("datetime");
// extracting date
result = result.substring(0, 10);
// reformatting to convert it to dd/MM/yyyy from yyyy/MM/dd
String internetDate = result.substring(8, 10) + "-" + result.substring(5, 7) + "-" + result.substring(0, 4);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
noElection.setText(error.getMessage());
noElection.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
}
});
queue.add(stringRequest);
}