Reputation: 5060
I have a string Apr. 20, 2013 Saturday @ 7:00 PM
and I am using below code:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMM. d, yyyy EEEE @ h:mm a"];
NSDate *dateFromString = nil;
dateFromString = [dateFormatter dateFromString:dateString];
[dateFormatter release];
and I am getting the result as 2000-01-01 13:30:00 +0000
. It is giving me wrong in iOS 6.
Upvotes: 0
Views: 308
Reputation: 1076
You have to do like this:
NSDate *today = [[NSDate alloc] init];
NSDateFormatter *aux = [[NSDateFormatter alloc] init];
[aux setDateFormat: @"MMM. d, yyyy EEEE @ h:mm a"];
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"es_ES"]; // Your locale, recommended 'en_US', 'en_GB', etc...
[aux setLocale:locale];
NSString *date = [aux stringFromDate: today];
BTW: you have to initialize your NSDate
variable, if you assign it to a nil
value then probably it won't work as desired like it's happening.
EDIT1: Probably you want to use this date format:
[dateFormat setDateFormat: @"EE, dd MMM yyyy '-' HH:mm"];
Upvotes: 1