iOS 获取日期对应的星期

作者: vision_colion | 来源:发表于2017-11-14 10:24 被阅读48次
    - (NSString*)weekdayStringFromDate:(NSDate*)inputDate {
        NSArray *weekdays = [NSArray arrayWithObjects: [NSNull null], @"星期天", @"星期一", @"星期二", @"星期三", @"星期四", @"星期五", @"星期六", nil];
        NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
        NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/Shanghai"];
        [calendar setTimeZone: timeZone];
        NSCalendarUnit calendarUnit = NSCalendarUnitWeekday;
        NSDateComponents *theComponents = [calendar components:calendarUnit fromDate:inputDate];
        return [weekdays objectAtIndex:theComponents.weekday];
    }
    

    相关文章

      网友评论

      本文标题:iOS 获取日期对应的星期

      本文链接:https://www.haomeiwen.com/subject/mzexvxtx.html