将一个日期转化成星期几

- (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];

}

推荐阅读更多精彩内容