1

使用 iOS 6 一切正常,但使用 iOS 5 myDate 返回 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];

我相信这一定是 DateFormat 的问题

4

2 回答 2

1
NSDate *today = [NSDate dateWithTimeIntervalSinceNow:0];
 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
 [dateFormat setDateStyle:NSDateFormatterShortStyle];
 NSString *dateString = [dateFormat stringFromDate:today];
 NSLog(@"Date: %@", dateString);
于 2012-07-10T13:26:13.513 回答
-1

这对我有用:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/MM/yyyy hh:mm:ss a"];
NSLog(@"%@", [dateFormatter dateFromString:@"12/12/2012 12:12:12 AM"]);
于 2012-07-10T12:52:28.553 回答