iOS 获取当前日期星期几

96
任任run
2017.03.20 16:32* 字数 68

//获取当前日期星期几

NSArray *weekdays = [NSArray arrayWithObjects:@"周日", @"周一", @"周二", @"周三", @"周四", @"周五", @"周六", nil];

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

[calendar setTimeZone: timeZone];

NSDate *date = [NSDate date];

NSCalendarUnit calendarUnit = NSWeekdayCalendarUnit;

NSDateComponents *theComponents = [calendar components:calendarUnit fromDate:date];

NSLog(@"%@", [weekdays objectAtIndex:theComponents.weekday]);

日记本