Reputation: 56
i'm beginner swift developer and i want to get user FIPS country codes like "EN" then apps Hour change to that country Time.
let CountryTime = String(NSDate.date(*/"EN"*/)) // -> return England Time
how can do it ?
Please advice. Thank you.
Upvotes: 1
Views: 2682
Reputation: 2778
Following TimeZone.init Returns a time zone initialized with a given identifier.If identifier is an unknown identifier, then returns nil.
let timezone = TimeZone.init(identifier: "America/Los_Angeles")
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "HH:mm"
dateFormatter.timeZone = timezone
print(dateFormatter.string(from: Date()))
Also to check the timeZone identifier list you can use this to get list.
print("Time zone list %@",TimeZone.knownTimeZoneIdentifiers)
Upvotes: 4