Я получаю с моего сервера дату строки в часовой пояс UTC, и мне нужно преобразовать ее в локальный часовой пояс.
МОЙ КОД:
let utcTime = "2015-04-01T11:42:00.269Z"
let dateFormatter = NSDateFormatter()
dateFormatter.timeZone = NSTimeZone(name: "UTC")
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
let date = dateFormatter.dateFromString(utcTime)
println("utc: \(utcTime), date: \(date)")
этот отпечаток -
utc: 2015-04-01T11: 42: 00.269Z, дата: необязательно (2015-04-01 11:42:00 +0000)
если я удалю
dateFormatter.timeZone = NSTimeZone(name: "UTC")
он печатает
utc: 2015-04-01T11: 42: 00.269Z, дата: необязательно (2015-04-01 08:42:00 +0000)
мой локальный часовой пояс UTC +3 и в первом варианте я получаю UTC во втором варианте я получаю UTC -3
Я должен получить
utc: 2015-04-01T11: 42: 00.269Z, дата: необязательно (2015-04-01 14:42:00 +0000)
Итак, как мне преобразовать формат даты UTC в локальное время?