最近有使用到日期获取,这里重新记一下算是复习
NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *comps = [[NSDateComponents alloc] init];
NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |
NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
NSDate *now=[NSDate date];
comps = [calendar components:unitFlags fromDate:now];
NSLog(@"weekday is %d",[comps weekday]);//注意:星期日是数字1,星期一时数字2,以此类推。。。
NSLog(@"month is %d",[comps month]);
NSLog(@"day is %d",[comps day]);
NSLog(@"weekdayOrdinal is %d",[comps weekdayOrdinal]);
网友评论