0

The code below is displays the time and time zone. It works but returns different results on my Mac (and simulator) to on my real iPhone. The first part is fine because it displays the 12 or 24 hour clock as set on the device (which is what I want). Unfortunately, the time zone is coming out as a GMT offset on the phone rather than as the local time zone name as on the Mac.

Question: How do I make the time zone display as EST on the iPhone?

let zone     = TimeZone(identifier: "America/New_York")
let f1       = DateFormatter()
f1.timeZone  = zone
f1.timeStyle = .short
let f2        = DateFormatter()
f2.timeZone   = zone
f2.dateFormat = "z"
print("\(f1.string(from: Date())) \(f2.string(from: Date()))")

Prints 2:14 pm EST on the Mac or iPhone simulator.

Prints 14:14 GMT-5 on the iPhone.

Both the iPhone and the MacBook are set to "English (UK)" language with the region set to "United Kingdom".

Vince O'Sullivan
  • 2,611
  • 32
  • 45
  • EST ist just one of several GMT-5 timezones, another would be Peru Time Zone, maybe it helps if you set a coordinate for your simulator http://stackoverflow.com/questions/214416/set-the-location-in-iphone-simulator – vikingosegundo Jan 06 '17 at 13:23
  • hover over countries to see other timezones: https://www.timeanddate.com/time/map/ – vikingosegundo Jan 06 '17 at 13:28
  • Thanks for your response. I am aware that there are many different timezone abbreviations (even within a single timezone). The question is how to display any of them on the iPhone. Currently, I am just getting a GMT offset (e.g. GMT-5) even though the same code displays the correct abbreviation on a Mac. Perhaps it is a limitation of iOS compared to MacOS. – Vince O'Sullivan Jan 07 '17 at 14:55

0 Answers0