【发布时间】:2013-06-20 04:57:45
【问题描述】:
我已经搜索了这个问题,但没有找到一个确凿而优雅的解决方案。无论如何要更改 NSDateFormatterFullStyleyear 以抑制年份信息。我正在使用代码:
NSString *dateDescription;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[dateFormatter setTimeZone:gmt];
[dateFormatter setDateStyle:NSDateFormatterFullStyle];
dateDescription = [dateFormatter stringFromDate:date];
NSLog(@"%@", dateDescription);
结果:2013 年 3 月 13 日,星期三
问候, 马科斯
【问题讨论】:
-
只是带有 dateDescription = [dateDescription substringWithRange:NSMakeRange(0, dateDescription.length-6); 的子字符串
-
@ices_2 如果用户的语言环境将日期放在字符串末尾以外的位置,那将无法正常工作。
-
但字符串可能因定义的用户语言环境而异。
-
[dateFormatter setDateFormat:@"EEEE, MMMM d"];
-
@ices_2 但是这样做会阻止日期在用户当前的语言环境中正确显示。
标签: ios objective-c nsdate nsdateformatter