NSDateFormatter始终返回2010-12-31 23:00:00 +0000

时间:2011-01-12 01:55:13

标签: iphone nsdate nsdateformatter

我正在使用此代码从字符串格式化日期:

NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"EEEE, dd MMMM yyyy"];

NSDate *dateStart = [dateFormat dateFromString:[thisEvent dateEvent]];

[thisEvent dateEvent]包含此日期:Saturday, 09 April 2011

我不知道为什么dateStart包含2010-12-31 23:00:00 +0000

我错了吗?

谢谢!!

1 个答案:

答案 0 :(得分:2)

当您希望打印日期时,它将是o.k -

     NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
    [dateFormat setDateFormat:@"EEEE, dd MMMM yyyy"];

    NSDate *dateStart = [dateFormat dateFromString:@"Saturday, 09 April 2011"];

    NSString *formattedDateString = [dateFormat stringFromDate:dateStart];
    NSLog(@"%@",formattedDateString);//returns "Saturday, 09 April 2011"//

希望有所帮助

SHANI