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

TimoP
  • 51
  • 3
  • The problem is with the `:` in the time zone information. This is not support by the `NSDateFormatter`. This has been asked before. See: http://stackoverflow.com/questions/3094819/nsdateformatter-returning-nil-in-os-4-0 – rckoenes Jul 10 '12 at 12:46

2 Answers2

1
NSDate *today = [NSDate dateWithTimeIntervalSinceNow:0];
 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
 [dateFormat setDateStyle:NSDateFormatterShortStyle];
 NSString *dateString = [dateFormat stringFromDate:today];
 NSLog(@"Date: %@", dateString);
venkat
  • 762
  • 2
  • 8
  • 20
-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"]);
MobileGeek
  • 2,462
  • 1
  • 26
  • 46