Date Format String returned by Sina Weibo API

Source: Internet
Author: User
Tags dateformat

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 ;}

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.