I work with Swift 3 and consume a date string from a YQL endpoint, which is in format Sat, 04 Mar 2017 03:40 AM GMT. This works well with multiple time zones (GMT, EST ...), but when using, for example, JST or CET, it does not understand - apparently because these are abbreviated names of time zones.
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEE, dd MMM yyyy hh:mm a Z"
var origin = dateFormatter.date(from: "Sat, 04 Mar 2017 03:40 AM JST")
origin = dateFormatter.date(from: "Sat, 04 Mar 2017 03:40 AM GMT")
A simple solution would be to access the date components and assign the time zone with components.timeZone = TimeZone(abbreviation: "JST")and create a new date object, but that just makes it all too ugly. I also tried to set the language with dateFormatter.locale = Locale(identifier: "en_US_POSIX"), but it did not matter, and the time zone identifier was like zzzor zzzall of the possible options.
Is there something that I'm missing or can't quickly understand the shortened time zone in a line?
source
share