3

我已经搜索了这个问题,但没有找到一个确凿而优雅的解决方案。无论如何要更改 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 日,星期三

问候, 马科斯

4

1 回答 1

5

以下是最接近的,无需大量棘手的字符串处理。调用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];
于 2013-06-23T16:35:49.493 回答