Sina Weibo returns the GMT time with the time zone. at ordinary times, it is used to the Chinese time representation format, and the GMT time cannot be converted for a while. After searching for a while, I finally found the corresponding time format string:
Tue May 31 17:46:55 +0800 2011
Corresponding:
EEE MMM d HH:mm:ss Z yyyy
Are ing relationships, where Z should be zone, indicating the meaning of the time zone, corresponding to the above + 0800 (Beijing time, is the UTC + 8 time zone ).
IOS resolution supplement:
If you parse the date format of Sina Weibo in iOS, you only set the dateformat attribute of the nsdateformatter instance to the preceding format string. It can be parsed in a simulator (provided that the simulator is "set"-> "multi-language environment"-> "UK/us"), but when debugging on a real machine, but cannot be parsed.
This is because the operating system environments in China are generally "China", "Hong Kong", and "Macao, China ", the preceding formatted string is valid only in the English operating system environment.
Therefore, to ensure that all settings can be parsed, we need to set the locale attribute of the nsdateformatter instance (forced conversion using "En-us ):
Example:
// Parse date + (nsstring *) resolvesinaweibodate in Sina Weibo :( nsstring *) Date {nsdateformatter * iosdateformater = [[[nsdateformatter alloc] init] autorelease]; iosdateformater. dateformat = @ "eee Mmm D hh: mm: ss z yyyy"; // required; otherwise, iosdateformater cannot be parsed. locale = [[[nslocale alloc] initwithlocaleidentifier: @ "en_us"] autoreler]; nsdate * Date = [iosdateformater datefromstring: date]; // target format nsdateformatter * resultformatter = [[nsdateformatter alloc] init] autorelter]; [resultformatter setdateformat: @ "mm dd hh: mm"]; return [globalinstance nsdatetonsstring: date withformatter: resultformatter];}
/** Convert a date to a date format string */-(nsstring *) nsdatetonsstring :( nsdate *) date withformatter :( nsdateformatter *) formatter {nsstring * datestring = [formatter stringfromdate: DATE]; return datestring ;}