从NSDateFormatterFullStyle字符串中删除年份

vil*_*lam 3 objective-c nsdate nsdateformatter ios

我搜索过这个问题并没有找到一个确凿而优雅的解决方案.无论如何都要更改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);
Run Code Online (Sandbox Code Playgroud)

结果:2013年3月13日,星期三

此致,马科斯

rma*_*ddy 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];
Run Code Online (Sandbox Code Playgroud)