NSDateFormatter:IST无法识别

时间:2015-04-24 11:54:20

标签: nsdateformatter date-format

NSDateFormatter无法识别IST时区。 确认以下日期

let dateString = "Jun 10, 2015 @ 12.30 AM PDT"
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MMM-dd-yyyy @ hh-mm-a-zzz"
let date = dateFormatter.dateFromString(dateString)

但无法识别IST时区的时间。

let dateString = "Jun 10, 2015 @ 12.30 AM IST"
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MMM-dd-yyyy @ hh-mm-a-zzz"
let date = dateFormatter.dateFromString(dateString)

IST时区的日期为零。

1 个答案:

答案 0 :(得分:0)

作为一种解决方法,这有助于:

let dateString = "Jun 10, 2015 @ 12.30 AM"
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MMM-dd-yyyy @ hh-mm-a"
dateFormatter.timeZone = NSTimeZone(abbreviation: "IST")
let date = dateFormatter.dateFromString(dateString)