Kulwinder Singh Rahal
Kulwinder Singh Rahal

Reputation: 519

Get TimeZone by lat and long in android?

I need Time Zone by lat,long ,for that I have found this post helpful Get Time Zone From Lat Long. As described in this link if I use Google Api then its response is

 {
        "dstOffset" : 3600,
       "rawOffset" : -18000,
       "status" : "OK",
       "timeZoneId" : "America/New_York",
       "timeZoneName" : "Eastern Daylight Time"
    }

but my requirement is that if India`s Time Zone is 5:30 then I need it to be 5.5 or if Any country time zone is 7:0 then 7.0. My question is how I get timezone from lat long also in custom form as specified above

Upvotes: 0

Views: 2525

Answers (1)

AwaisMajeed
AwaisMajeed

Reputation: 2314

this line may help you.....

double zone = (responseObject.get("rawOffset").getAsInt() + responseObject.get("dstOffset").getAsInt()) / 3600.0;

get rawOffset and dstOffset from the response and add them, and divide them on 3600..... rawOffset is the GMT +- timezone in seconds and dstOffset is daylight saving offset in second (if a country is having dst it will be 3600 else 0)

Upvotes: 1

Related Questions