0
 NSString *dateString = @"13-8-06 10:53:54 +0300";
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    // this is imporant - we set our input date format to match our input string
    // if format doesn't match you'll get nil from your string, so be careful
    [dateFormatter setDateFormat:@"yy-MM-dd HH:mm 'ZZ'"];
    NSDate *dateFromString = [[NSDate alloc] init];
    // voila!
    dateFromString = [dateFormatter dateFromString:dateString];

dateFromString 为零。有谁知道我应该给 NSDateFormatter 哪种格式?

4

4 回答 4

0

您必须将日期格式设置为

@"dd-MM-yy HH:mm:ss ZZZ"
于 2013-09-05T06:02:33.527 回答
0
    NSString *dateString = @"13-8-06 10:53:54 +0300";
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yy-M-dd HH:mm:ss Z"];
    NSDate *date = [dateFormatter dateFromString:dateString];
    NSLog(@"%@",date);
于 2013-09-05T06:21:50.247 回答
0

尝试这个[dateFormatter setDateFormat:@"yy-MM-dd HH:mm:ss ZZ"];

于 2013-09-05T06:22:21.487 回答
0

尝试这个

NSString *dateString = @"13-8-06 10:53:54 +0300";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd-MM-yy HH:mm:ss ZZZ"];
NSDate *date =[dateFormatter dateFromString:dateString];
NSLog(@"%@",date);
[dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss ZZZ"];
dateString =[dateFormatter stringFromDate:date];
NSLog(@"%@",dateString);
于 2013-09-04T12:30:55.283 回答