根据日期算出星期几

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

  NSArray *weekdays = [NSArray arrayWithObjects: [NSNull null], @"周日", @"周一", @"周二", @"周三", @"周四", @"周五", @"周六", nil]; 
  
  NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 
  
  NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/Shanghai"]; [calendar setTimeZone: timeZone]; 
 
   NSCalendarUnit calendarUnit = NSWeekdayCalendarUnit; 
  
  NSDateComponents *theComponents = [calendar components:calendarUnit fromDate:inputDate];
 
  return [weekdays objectAtIndex:theComponents.weekday];
}```

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