【发布时间】:2013-10-07 19:11:47
【问题描述】:
当日历设置为日语时,我正在尝试显示 NSDate 的 4 位公历年份。
NSLog(@"Date joined: %@", self.dateJoined);
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.calendar = calendar;
formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
formatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"EST"];
formatter.dateFormat = @"yyyy";
NSLog(@"Year joined: %@", [formatter stringFromDate:self.dateJoined]);
日志:
Date joined: 2012-05-29 22:13:54 +0000
Year joined: 4000
我做错了什么?
【问题讨论】:
-
你试过“en_US_POSIX”而不是“en_US”吗?
-
@MartinR 我刚试了一下,结果是一样的。
标签: ios objective-c nsdate nsdateformatter