NSDate *date = [NSDate date];//这个是NSDate类型的日期,所要获取的年月日都放在这里;NSCalendar *cal =[NSCalendar currentCalendar]; unsigned int unitFlags = NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay;//这句是说你要获取日期的元素有哪些。获取年就要写NSYearCalendarUnit,获取小时就要写NSHourCalendarUnit,中间用|隔开;
NSDateComponents *d = [cal components:unitFlags fromDate:date];//把要从date中获取的unitFlags标示的日期元素存放在NSDateComponents类型的d里面; //然后就可以从d中获取具体的年月日了;
NSInteger year =[d year];
NSInteger month =[d month];
NSInteger day =[d day];
NSLog(@"%ld",year);
NSLog(@"%ld",month);
NSLog(@"%ld",day);
oc之获取系统当前时间的方法
免责声明:文章转载自《oc之获取系统当前时间的方法》仅用于学习参考。如对内容有疑问,请及时联系本站处理。
上篇Mybatis的@Options注解查看IP和MAC地址的命令下篇
宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=