IT虾米网

ios怎么判断日期是周末

sanshao 2018年06月24日 手机开发 906 0
    - (NSString *)calculateWeek:(NSDate *)date{   
        //计算week数   
        NSCalendar * myCalendar = [NSCalendar currentCalendar];   
        myCalendar.timeZone = [NSTimeZone systemTimeZone];   
        NSInteger week = [[myCalendar components:NSWeekdayCalendarUnit fromDate:date] weekday];   
        NSLog(@"week : %zd",week);   
        switch (week) {   
            case 1:   
            {   
                return @"周日";   
            }   
            case 2:   
            {   
                return @"周一";   
            }   
            case 3:   
            {   
                return @"周二";   
            }   
            case 4:   
            {   
                return @"周三";   
            }   
            case 5:   
            {   
                return @"周四";   
            }   
            case 6:   
            {   
                return @"周五";   
            }   
            case 7:   
            {   
                return @"周六";   
            }   
        }   
           
        return @"";   
    }  

评论关闭
IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!