IPhone development Note (18) converts the date in the HTTP header to nsdate

Source: Internet
Author: User

1. Get the HTTP Header

I have defined the global variable mycache of asidownloadcache in appdelegate.

 
Appdelegate * appdelegate = [[uiapplication sharedapplication] Delegate]; nsdictionary * DIC = [appdelegate. mycache cachedresponseheadersforurl: [nsurl urlwithstring: @ "http ://...... /getpicturenews. aspx "];

Output DIC And get the following result:

 
{"Cache-control" = private; "Content-Length" = 2404; "Content-Type" = "text/html; charset = UTF-8"; Date = "Sun, 07 Oct 2012 06:13:41 GMT "; server =" Microsoft-IIS/6.0 ";" X-asihttprequest-fetch-Date "=" Sun, 07 Oct 2012 06:13:44 GMT "; "X-ASPnet-version" = "2.0.50727"; "X-powered-by" = "ASP. net ";}

2. Get date and convert

Nsstring * lastupdate = [DIC objectforkey: @ "date"]; nsdateformatter * formatter = [[nsdateformatter alloc] init]; [formatter setdateformat: @ "eee ', 'dd' 'mmm' 'yyyy HH ': 'mm': 'ss Zzz "]; nsdate * Date = [formatter datefromstring: lastupdate]; nslog (@" % @", date );

The output date is

06:13:44 + 0000

3. Summary

The key is that the formatter string of nsdateformatter should be correctly written, and other things can be done after the date is obtained. There is no difference in performing other date operations.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.