zoukankan      html  css  js  c++  java
  • 星期判断

    /**  是否为周末  */
    + (BOOL)isWeekday
    {
        NSInteger year,month,day,hour,min,sec,week;
    
        NSString *weekStr=nil;
    
        NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    
        NSDate *now = [NSDate date];;
    
        NSDateComponents *comps = [[NSDateComponents alloc] init];
    
        NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit |
    
        NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    
        comps = [calendar components:unitFlags fromDate:now];
    
        year = [comps year];
    
        week = [comps weekday];
    
        month = [comps month];
    
        day = [comps day];
    
        hour = [comps hour];
    
        min = [comps minute];
    
        sec = [comps second];
    
        BOOL isWeekend = NO;
    
        if(week == 1){
            weekStr=@"星期天";
    
            isWeekend = YES;
        }else if(week == 2){
    weekStr
    =@"星期一"; }else if(week == 3){ weekStr=@"星期二"; }else if(week == 4){ weekStr=@"星期三"; }else if(week==5){ weekStr=@"星期四"; }else if(week == 6){ weekStr=@"星期五"; }else if(week == 7){ weekStr=@"星期六"; isWeekend = YES; } NSLog(@"现在是:%ld年%ld月%ld日 %ld时%ld分%ld秒 %@", (long)year,(long)month,(long)day,(long)hour,(long)min,(long)sec,weekStr); return isWeekend; }
  • 相关阅读:
    城市的划入划出效果
    文本溢出省略解决笔记css
    长串英文数字强制折行解决办法css
    Poj 2352 Star
    树状数组(Binary Indexed Trees,二分索引树)
    二叉树的层次遍历
    Uva 107 The Cat in the Hat
    Uva 10336 Rank the Languages
    Uva 536 Tree Recovery
    Uva10701 Pre, in and post
  • 原文地址:https://www.cnblogs.com/Milo-CTO/p/4806675.html
Copyright © 2011-2022 走看看