I want to retrieve GMT(5.5) of India or same like this for other Country. Below is my code where I used Google Time Zone API and the coming response is on dstoffset, rawOffset, status, timeZoneId, timeZoneName. My question is how to get GMT (5.5) Thank you
final String registerURL = "https://maps.googleapis.com/maps/api/timezone/json?location=30.293461,78.524094×tamp=1331161200&key=API_KEY";
StringRequest stringRequest = new StringRequest(Request.Method.POST, registerURL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject obj = new JSONObject(response);
String s1 = obj.getString("dstOffset");
String s2 = obj.getString("rawOffset");
String s3 = obj.getString("status");
String s4 = obj.getString("timeZoneId");
String s5 = obj.getString("timeZoneName");
TimeZone tz1 = TimeZone.getTimeZone(s4);
TimeZone tz2 = TimeZone.getTimeZone(s4);
tvTimeZone.setText(String.valueOf(tz2));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
// Handles errors that occur due to Volley
public void onErrorResponse(VolleyError error) {
Log.e("Volley", "Error");
}
}
);
RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
requestQueue.add(stringRequest);
rawOffset
is documented: developers.google.com/maps/documentation/timezone/…rawOffset
is in seconds, what is wrong with dividing that amount by 3600 seconds (the number of seconds in a hour) to get UTC hours? And UTC is the same as GMT.