我正在尝试获取 URLResponse 的最后修改属性作为 NSDate。我按照以下指示进行操作:
但它们都不起作用..我从 URLResponse-Object 中正确收到日期作为字符串,格式为“Mon, 19 Oct 2015 05:57:12 GMT”
我需要将此字符串转换为 NSDate 以便能够将其与 NSDate 形式的 localDate 进行比较:2015-10-19 05:57:12 UTC
我也尝试过不同的日期格式,但没有任何区别。
我当前的代码如下:
//The serverDate needs to match the localDate which is a
//NSDate? with value: 2015-10-19 05:57:12 UTC
if let httpResp: NSHTTPURLResponse = response as? NSHTTPURLResponse {
let date = httpResp.allHeaderFields["Last-Modified"] as! String //EXAMPLE: "Mon, 19 Oct 2015 05:57:12 GMT"
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat …Run Code Online (Sandbox Code Playgroud)