我知道有很多类似的问题,但我无法弄清楚我的问题。
我想将 String
转换为 NSDate。
我的代码如下。
let date:String
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ssZ"
if let value = row["date"]?.asString() {
date = value
let formattedDate = dateFormatter.dateFromString(date) // formattedDate is nil
}
最佳答案
您需要使用以下内容更新您的dateFormat
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSSSSS"
因为大写的 S
代表秒的分数。
有关日期时间格式表的更多详细信息可用 here
关于swift - NSDateFormatter dateFromString 为 "2015-11-20 13:42:00.000000"返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34150123/