============================================================
博文原创,转载请声明出处
============================================================
IOS日期NSDateFormatter方法
NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init]autorelease];
[dateFormatter setDateFormat:@"h:MM:ss a"];
NSString* dataStr = [dateFormatter stringFromDate:[NSDate date]];
Appendix F: Date Format Patterns
A date pattern is a string of characters, where specific strings of characters are replaced with date and time data from a calendar when formatting or used to generate data for a calendar when parsing. The following are the characters used in patterns to show the appropriate formats for a given locale. The following are examples:
Pattern | Result (in a particular locale) |
---|---|
yyyy.MM.dd G 'at' HH:mm:ss zzz | 1996.07.10 AD at 15:08:56 PDT |
EEE, MMM d, ''yy | Wed, July 10, '96 |
h:mm a | 12:08 PM |
hh 'o''clock' a, zzzz | 12 o'clock PM, Pacific Daylight Time |
K:mm a, z | 0:00 PM, PST |
yyyyy.MMMM.dd GGG hh:mm aaa | 01996.July.10 AD 12:08 PM |