1

With iOS 6 everything is ok but with iOS 5 myDate return nil

NSString *dateString = @"2012-07-12T11:00:00+02:00";

NSLocale *deLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"de_DE"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY-MM-dd'T'HH:mm:ssZZZZ"];
dateFormatter.locale = deLocale;
NSDate *myDate = [dateFormatter dateFromString:dateString];

It must be a Problem with the DateFormat i believe

1

2 Answers 2

1
NSDate *today = [NSDate dateWithTimeIntervalSinceNow:0];
 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
 [dateFormat setDateStyle:NSDateFormatterShortStyle];
 NSString *dateString = [dateFormat stringFromDate:today];
 NSLog(@"Date: %@", dateString);
0
-1

This works for me:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/MM/yyyy hh:mm:ss a"];
NSLog(@"%@", [dateFormatter dateFromString:@"12/12/2012 12:12:12 AM"]);
1
  • Great that it work for you, but the date that you parse does not match the on given by @TimoP
    – rckoenes
    Jul 10, 2012 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.