美文网首页iOS
iOS中根据当前日期判断是星期几

iOS中根据当前日期判断是星期几

作者: Youthfulless | 来源:发表于2016-11-30 10:32 被阅读113次

    NSCalendar *calendar = [[NSCalendaralloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

    NSDate *now = [NSDate date];

    NSDateComponents *comps = [[NSDateComponentsalloc] init];

    NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |

    NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;

    calendar.locale = [[NSLocalealloc] initWithLocaleIdentifier:@"zh_CN"];

    comps = [calendar components:unitFlags fromDate:now];

    long week = [comps weekday];

    NSLog(@"week=============%ld",week);

    相关文章

      网友评论

        本文标题:iOS中根据当前日期判断是星期几

        本文链接:https://www.haomeiwen.com/subject/dnazpttx.html