2

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&timestamp=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);
7
  • Please edit your question with what problem you are having as rawOffset is documented: developers.google.com/maps/documentation/timezone/… Commented Jun 16, 2018 at 6:37
  • Actually sir, I want to get GMT(5.5) of India, how can I get that please suggest. Commented Jun 16, 2018 at 6:56
  • Since 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. Commented Jun 16, 2018 at 7:06
  • Okay I got it, Thank you Sir. Commented Jun 16, 2018 at 7:09
  • I also checked for Asia/Kabul where "rawOffset" : 16200 and divide it from 3600 the result is 4.5 but the GMT of Asia/Kabul is 4.30. Commented Jun 16, 2018 at 7:16

1 Answer 1

4

rawOffset is the offset from UTC (in seconds) for the given location.

As UTC and GMT has no time difference between them, dividing rawOffset by 3600 you can get the GMT time of your requested time zone.

And obviously, when divided by 3600, the answer is in fractions of hour not in the hour:min pair. So, if you get the output, say, 4.50, that is actually 4.5 hours which is the same as 4:30 hours (4 hours 30 minutes).

1
  • It is correct, If dstOffset is equal to zero, But, if dstOffset is not equal to zero , need to add dstOffset with rawOffset Commented Jun 5, 2020 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.