ios - 将 String 转换为 NSDate 奇怪的格式

标签 ios xcode swift

我认为我的字符串日期格式很奇怪,但我有以下代码:

let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let date = dateFormatter.dateFromString(subJson["lastSyncTime"].string!)

我的 subJson["lastSyncTime"].string = 2015-07-30T11:44:37.070

不确定我做错了什么,因为我是 swift 的新手。中间的T好像搞砸了?但是变量“date”= nil

最佳答案

日期字符串是 ISO 8601 格式的日期,所以使用这种格式

dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"

关于ios - 将 String 转换为 NSDate 奇怪的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31732489/

相关文章:

ios - 以编程方式将 UiView 作为 subview

ios - UITableView - 出现在单元格之间的线

ios - 在 ios react-native 中打开应用程序设置

ios - 代码 9 : Setting RootViewController in AppDelegate causes black screen after launching the application

iphone - 为 iPhone SDK (XCode) 编译 Freetype

swift - 仅当 loadRequest 位于 viewDidLoad 之外时,UIWebView 才会出现 Nil 错误

ios - 使用 UITableViewDiffableDataSource 创建章节标题

swift - 无法在新的 Xcode 10.2 (iOS 12.2) 中构建 Alamofire 框架

objective-c - Xcode:在调试中确定 xcode 中函数的调用者

ios - navigationItem.titleView 上的 UITapGestureRecognizer 在 iOS 11 上不起作用