iOS 输入日期转化为星期
/**
* 输入日期转化为星期
*/
+ (NSString*)weekdayStringFromDate:(NSDate*)inputDate {
NSArray *weekdays = [NSArray arrayWithObjects:[NSNull null], @"7", @"1", @"2", @"3", @"4", @"5", @"6",nil];
NSCalendar * calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/Shanghai"];
[calendarsetTimeZone: timeZone];
NSCalendarUnit calendarUnit = NSCalendarUnitWeekday;
NSDateComponents* theComponents = [calendarcomponents:calendarUnitfromDate:inputDate];
return[weekdaysobjectAtIndex:theComponents.weekday];
}
/**
* 日期转星期
*/
+ (NSString*)weekConversionDay:(NSString*)date {
if ([[NSString stringWithFormat:@"%@",[ZSDate weekdayStringFromDate:[ZSDate convertDateFormatStringToNSDateObjects:date]]] isEqualToString:@"1"]) {
return@"周一";
}else if([[NSString stringWithFormat:@"%@",[ZSDate weekdayStringFromDate:[ZSDate convertDateFormatStringToNSDateObjects:date]]] isEqualToString:@"2"]) {
return@"周二";
}else if([[NSString stringWithFormat:@"%@",[ZSDate weekdayStringFromDate:[ZSDate convertDateFormatStringToNSDateObjects:date]]] isEqualToString:@"3"]) {
return@"周三";
}else if([[NSString stringWithFormat:@"%@",[ZSDate weekdayStringFromDate:[ZSDate convertDateFormatStringToNSDateObjects:date]]] isEqualToString:@"4"]) {
return@"周四";
}else if([[NSString stringWithFormat:@"%@",[ZSDate weekdayStringFromDate:[ZSDate convertDateFormatStringToNSDateObjects:date]]] isEqualToString:@"5"]) {
return@"周五";
}else if([[NSString stringWithFormat:@"%@",[ZSDate weekdayStringFromDate:[ZSDate convertDateFormatStringToNSDateObjects:date]]] isEqualToString:@"6"]) {
return@"周六";
}else if([[NSString stringWithFormat:@"%@",[ZSDate weekdayStringFromDate:[ZSDate convertDateFormatStringToNSDateObjects:date]]] isEqualToString:@"7"]) {
return@"周日";
}
return nil;
}