Get TimeZone by lat and long in android?

风流意气都作罢 提交于 2019-12-12 04:35:52

问题


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


回答1:


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)



来源:https://stackoverflow.com/questions/45767424/get-timezone-by-lat-and-long-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!