iOS上運行10時,下面的代碼中出現死機的XCode 8(不上以前的IOS版本崩潰)NSDateFormatter回報爲零:在IOS10
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SS'Z'"
dateFormatter.timeZone = NSTimeZone(name: "UTC")
dateFormatter.locale = NSLocale.currentLocale()
let date = dateFormatter.dateFromString("2016-09-04T08:32:46.195514289Z")!
崩潰是因爲日期格式返回nil。我試圖播放和更改dateFormat,但結果始終爲零。 iOS 10中有什麼改變?
編輯:斯威夫特與運行3.當同一代碼在故事板看來,問題與雨燕2.3和iOS 10
無法重現。但是,使用固定日期格式時,將區域設置設置爲「en_US_POSIX」而不是當前區域設置總是一個好主意。這可能會解決你的問題。 –
關於當前的答案:請注意,「它適用於我」不被認爲是可接受的答案,比較http://meta.stackoverflow.com/questions/277923/are-your-code-works-fine-for -Me-答案可接受的。 –
即使使用Swift 2.3,我也無法重現。你嘗試過POSIX語言環境嗎? –