NSDateFormatter related Finishing

Source: Internet
Author: User

Formatter is translated into a format, the corresponding NSDateFormatter is equivalent to the NSDate conversion class, converting nsdate to another format, or converting it back. The nsdate does not have its own output and needs to be output in the appropriate format with NSDateFormatter. This is almost the nsdateformatter of the role of the bar.

The usual method is not complicated, just a few statements, and here is the whole process. Too lazy to write a direct copy of someone else's

Instantiate a NSDateFormatter object nsdateformatter *dateformatter = [[NSDateFormatter alloc] init];//set the time format, where you can set the format you want [ Dateformatter setdateformat:@ "Yyyy-mm-dd HH:mm:ss"];//with [NSDate Date] can get system current time nsstring *currentdatestr = [ Dateformatter stringfromdate:[nsdate date]];//output format: 2010-10-27 10:22:13nslog (@ "%@", currentdatestr);// Alloc after the non-use of objects do not forget release[dateformatter release];

Output formats by Setdatestyle and Settimestyle settings, respectively, define the format of the date and time optional system-given method

typedef enum {    Nsdateformatternostyle     = Kcfdateformatternostyle,    nsdateformattershortstyle  = kcfdateformattershortstyle,//"11/23/37" or "3:30pm"    Nsdateformattermediumstyle = kcfdateformattermediumstyle,/ /\ "Nov, 1937\"    nsdateformatterlongstyle   = kcfdateformatterlongstyle,//\ "November, 1937" or "3:30:32pm\"    Nsdateformatterfullstyle   = kcfdateformatterfullstyle//"Tuesday, April, 1952 AD" or "3:30:42pm PST"} Nsdateformatterstyle;

NSDateFormatter related Finishing

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.