cocoa 时间处理

By | 2014/05/06

cocoa 时间处理

获取当地的日期

 


NSCalendar *c = [[NSLocale currentLocale] objectForKey:NSLocaleCalendar];
        unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit | NSWeekdayCalendarUnit | NSWeekCalendarUnit;
        NSDate *date = [NSDate date];
        NSDateComponents *comps = ;
        NSLog(@"%ld",(long)comps.weekday);

给定任意年月日来确定周

 

        NSDateComponents *comps = [[NSDateComponents alloc] init];
        [comps setDay:1];
        [comps setMonth:5];
        [comps setYear:2014];
        NSCalendar *gregorian = [[NSCalendar alloc]
                                 initWithCalendarIdentifier:NSGregorianCalendar];
        NSDate *date = [gregorian dateFromComponents:comps];
        NSDateComponents *weekdayComponents =
        [gregorian components:NSWeekdayCalendarUnit fromDate:date];
        int weekday = (int)[weekdayComponents weekday];
        NSLog(@"%d",weekday);

求给定月份的天数

 


        NSDate *today = [NSDate date]; //Get a date object for today's date
        NSRange days = ;
        NSLog(@"%ld",days.length);

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.