iphone - How to get the timezone of a location in iOS app? -
this question has answer here:
i new ios development. trying build app can 2 things:
a. get user's system time (say, phone in london, time)
b. get time in given location (say, san francisco)
and then, want calculate difference in time between location (e.g. london, uk 8 hours ahead of san francisco, ca)
can please me suggestions how can (a) , (b)?
for both (a) , (b):
let offset = timezone.current.secondsfromgmt(); print(offset)//your current timezone offset in seconds let loc = cllocation.init(latitude: 48.8566, longitude: 2.3522);//paris's lon/lat let coder = clgeocoder(); coder.reversegeocodelocation(loc) { (placemarks, error) in let place = placemarks?.last; let newoffset = place?.timezone?.secondsfromgmt(); print(newoffset);//paris's timezone offset in seconds }
Comments
Post a Comment