我搜索过这个问题,但没有找到结论性且优雅的解决方案。无论如何,是否可以更改 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 日星期三
问候,
马科斯
以下是您将得到的最接近的结果,无需进行大量棘手的字符串处理。致电给dateFormatFromTemplate:options:locale:
将更新提供的模板以最好地匹配指定的区域设置。
这假设正常的“完整”样式为您提供工作日名称、月份名称和月份中的日期。
NSString *fullMinusYear = [NSDateFormatter dateFormatFromTemplate:@"EEEE, MMMM dd" options:0 locale:[NSLocale currentLocale]];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:fullMinusYear];
NSString *dateDescription = [dateFormatter stringFromDate:date];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)