根据日期求出星期

作者: JuniorYoung | 来源:发表于2016-03-29 10:14 被阅读38次

    + (NSString*)weekdayStringFromDate:(NSDate*)inputDate {

    NSArray*weekdays = [NSArrayarrayWithObjects: [NSNullnull],@"星期日",@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六",nil];

    NSCalendar*calendar = [[NSCalendaralloc]initWithCalendarIdentifier:NSGregorianCalendar];

    NSTimeZone*timeZone = [[NSTimeZonealloc]initWithName:@"Asia/Shanghai"];

    [calendarsetTimeZone: timeZone];

    NSCalendarUnitcalendarUnit =NSWeekdayCalendarUnit;

    NSDateComponents*theComponents = [calendarcomponents:calendarUnitfromDate:inputDate];

    return[weekdaysobjectAtIndex:theComponents.weekday];

    }

    相关文章

      网友评论

      本文标题:根据日期求出星期

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