我有一個包含日期的字符串。我試圖從字符串中獲取日期,但我沒有找到正確的格式。 這是字符串:不從字符串中獲取日期?
NSString *[email protected]"Thu, 07 Jan 2016 07:49:17 GMT";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss %Z"];
NSDate *lastDate = [dateFormatter dateFromString:lastModified];
lastDate
始終是零。 有什麼幫助嗎?謝謝!
編輯! 我不知道這是否是重要的,但日期是從頭部抽放的NSUrl
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:imageUrl];
[request setHTTPMethod:@"HEAD"];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue new] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSString *lastModified = [[httpResponse allHeaderFields] objectForKey:@"Last-Modified"];
我收到從NSUrl
Head
和需要檢查的Last-Modified
日期,並與數據庫中我比較日期。
這裏的HttpResponse:
<NSHTTPURLResponse: 0x15d00800> { URL: url } { status code: 200, headers {
"Accept-Ranges" = bytes;
Connection = "keep-alive";
"Content-Length" = 60065;
"Content-Type" = "image/png";
Date = "Thu, 07 Jan 2016 08:27:50 GMT";
Etag = "\"568d4c77-eaa1\"";
"Last-Modified" = "Wed, 06 Jan 2016 17:18:47 GMT";
Server = nginx;
"X-Powered-By" = PleskLin;
} }
這是所有的信息,我有。
試'[dateFormatter setDateFormat:@ 「EEE,DD MMM YYYY HH:MM:SS Z」];' – Mahesh
u能也嘗試這個EEE,DD MMM YYYY HH:mm:ss'GMT' –
沒有任何工作 –