views:

81

answers:

3

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 result is:

Wednesday, July 14, 2010

Does anyone have any idea of how to get this to just WORK ??

Appreciate your answers..

+3  A: 

setDateStyle: overrides the custom format string set with setDateFormat:.

Nikolai Ruhe
Thanks Man, appreciate it
zanque
A: 

See Apple's Date Formatting docs.

I haven't tested it, but try

 [dateFormat setDateFormat:@"MM/DD/yy"]; 
Rob Lourens
Not working tooi keep getting this:Wednesday, July 14, 2010
zanque
Nikolai's answer is right.
Rob Lourens
+3  A: 

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.

Georg Fritzsche
Whats really interesting is the format string is kind of uselessbecause no matter what you set the format string to be, i keep getting this format:Wednesday, July 14, 2010why, I DON'T KnowPS: i tried yours
zanque
THATS RIGHT!!!!Thank you
zanque