我想将“ 2014-07-15 06:55:14.198000 + 00:00”此字符串日期转换为Swift中的NSDate。
试试这个:
let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = /* find out and place date format from * http://userguide.icu-project.org/formatparse/datetime */ let date = dateFormatter.dateFromString(/* your_date_string */)
要进行进一步查询,请分别检查 Foundation 框架的Objective- C和Swift的NSDateFormatter和DateFormatter类。 __
Swift 3及更高版本(包括Swift 4)
let dateFormatter = DateFormatter() dateFormatter.dateFormat = /* date_format_you_want_in_string from * http://userguide.icu-project.org/formatparse/datetime */ guard let date = dateFormatter.date(from: /* your_date_string */) else { fatalError("ERROR: Date conversion failed due to mismatched format.") } // use date constant here