在Quick2.x中,我使用toDate函数来获得使用SwiftDate的iso日期。任何人都知道正确的替代办法:
let isoDate = stringDate.toDate(DateFormat.ISO8601Format(.Extended))在查看SwiftDate文档时,我尝试了这样的方法:
let isoDate = stringDate.date(format:.iso8601)但对格式的抱怨
编辑:
我将SwiftDate版本从4.0.7改为4.0.3,现在存在iso格式,但引发了一个错误
我的日期字符串:"2016-11-24T03:00:00.000Z"
let isoDate = try! dt.date(format: DateFormat.iso8601(options: .extended)).absoluteDate错误:键入'ISO8601DateTimeFormatter.Options‘没有成员’扩展‘
let isoDate = try! dt.date(format: DateFormat.iso8601(options: [])).absoluteDate错误:没有错误但抛出
在快速2.2中,我使用了完全相同的日期格式。
发布于 2016-11-23 17:08:28
SwiftDate 4.0.5
这是源文件
// The format used for internet date times; it's similar to .withInternetDateTime
// but include milliseconds ('yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ').
public static let withInternetDateTimeExtended = ISO8601DateTimeFormatter.Options(rawValue: 1 << 11)这是在当前最新版本(SwiftDate 4.0.7)上编译的:
let stringDate = "2016-11-24T03:00:00.000Z"
let options = ISO8601DateTimeFormatter.Options.withInternetDateTimeExtended
let format = DateFormat.iso8601(options: options)
let isoDate = try? stringDate.date(format: format)https://stackoverflow.com/questions/40767067
复制相似问题