iphone NSDate with NSDateFormatter Problem
All i am trying to do, is to get an NSString with the value of the current date ( NOW )
with this format:
7/14/10 8:20 PM
Exactly like the native mail app of the iPhone.
i am using the following code to do it:
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EEE, dd MMMM yyyy HH:mm:ss ZZ"];
[dateFormat setDateStyle:NSDateFormatterFullStyle];
NSString *dateString = [dateFormat stringFromDate:[NSDate date]];
but the still the开发者_StackOverflow社区 result is:
Wednesday, July 14, 2010
Does anyone have any idea of how to get this to just WORK ??
Appreciate your answers..
setDateStyle:
overrides the custom format string set with setDateFormat:
.
Besides that you should call -setDateStyle:
first as per Nikolai answer, your formatting string doesn't match your example, which would be produced by e.g. the following:
[dateFormat setDateFormat:@"M/d/yy h:mm a"];
See the Unicode date format patterns for more details.
See Apple's Date Formatting docs.
I haven't tested it, but try
[dateFormat setDateFormat:@"MM/DD/yy"];
精彩评论