Objective c NSDateFormatter存在问题

Objective c NSDateFormatter存在问题,objective-c,nsdate,Objective C,Nsdate,我不明白这为什么不起作用 NSDateFormatter * dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"dd MMMM YYYY"]; NSDate * complDate = [dateFormat dateFromString:@"27 June 2011"]; complDate返回2010-12-25 21:00:00+0000setDateFromat:函数,用于

我不明白这为什么不起作用

   NSDateFormatter * dateFormat = [[NSDateFormatter alloc] init];
   [dateFormat setDateFormat:@"dd MMMM YYYY"];
   NSDate * complDate = [dateFormat dateFromString:@"27 June 2011"];

complDate
返回
2010-12-25 21:00:00+0000

setDateFromat:
函数,用于格式化
stringFromDate:
函数的sting对象
dateFromString:
返回
NSDate
对象

文档中的示例:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd 'at' HH:mm"];

NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:162000];

NSString *formattedDateString = [dateFormatter stringFromDate:date];
NSLog(@"formattedDateString: %@", formattedDateString);
// For US English, the output may be:
// formattedDateString: 2001-01-02 at 13:00 

setDateFromat:
函数用于格式化
stringFromDate:
函数的sting对象
dateFromString:
返回
NSDate
对象

文档中的示例:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd 'at' HH:mm"];

NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:162000];

NSString *formattedDateString = [dateFormatter stringFromDate:date];
NSLog(@"formattedDateString: %@", formattedDateString);
// For US English, the output may be:
// formattedDateString: 2001-01-02 at 13:00 
您的格式字符串需要使用小写字母“y”:

[dateFormat setDateFormat:@"dd MMMM yyyy"];
大写字母“Y”表示“一年中的一周”。看,;它包含指向
NSDateFormatter
使用的Unicode格式说明符的链接。

格式字符串需要使用小写字母“y”:

[dateFormat setDateFormat:@"dd MMMM yyyy"];

大写字母“Y”表示“一年中的一周”。看,;它包含指向
NSDateFormatter
使用的Unicode格式说明符的链接。

NSDateFormatter*dateFormat=[[NSDateFormatter alloc]init];[日期格式setDateFormat:@“d MMMM yyyy”];NSDate*complDate=[dateFormat dateFromString:@“2011年6月27日”];结果是2011-06-26 20:00:00+000,这是由时区引起的;我相信日期格式化程序假定您希望默认情况下以GMT显示结果。使用
setTimeZone:
使其使用系统的时区值。将时区设置为[dateFormat setTimeZone:[NSTimeZone timezonewibbrevision:@“MSK”];没有帮助,但有一些神奇的东西:[dateFormat setDateFormat:@“MMM d”];NSString*dateStr=[dateFormat stringFromDate:complDate];[日期格式发布];为我提供正确的DateNSDateFormatter*dateFormat=[[NSDateFormatter alloc]init];[日期格式setDateFormat:@“d MMMM yyyy”];NSDate*complDate=[dateFormat dateFromString:@“2011年6月27日”];结果是2011-06-26 20:00:00+000,这是由时区引起的;我相信日期格式化程序假定您希望默认情况下以GMT显示结果。使用
setTimeZone:
使其使用系统的时区值。将时区设置为[dateFormat setTimeZone:[NSTimeZone timezonewibbrevision:@“MSK”];没有帮助,但有一些神奇的东西:[dateFormat setDateFormat:@“MMM d”];NSString*dateStr=[dateFormat stringFromDate:complDate];[日期格式发布];给我正确的日期