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