Day Name From NSDate?

前端 未结 6 1580
礼貌的吻别
礼貌的吻别 2020-12-15 16:29

I would like to show the name of day in my iPhone application and i don\'t found the solution. Thanks for help

6条回答
  •  鱼传尺愫
    2020-12-15 16:46

    NSDate category

    + (NSString *)dayNameWith0Monday:(NSInteger)index {
    
        static NSDateFormatter * DateFormatter = nil;
        if (DateFormatter == nil) {
            DateFormatter = [[NSDateFormatter alloc] init];
            [DateFormatter setDateFormat:@"EEEE"];
            [DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
        }
    
        NSDate * day = [NSDate dateWithTimeIntervalSince1970:((4 * 24 * 60 * 60) + (24 * 60 * 60 * index))];
        return [DateFormatter stringFromDate:day];
    }
    

    0 will always be Monday! in case you need such behaviour

提交回复
热议问题