根据日期求出星期

这是个根据日期求出星期几的类方法:


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

}

你可能感兴趣的:(根据日期求出星期)