取得NSDate实例各个字段的数字
生活随笔
收集整理的這篇文章主要介紹了
取得NSDate实例各个字段的数字
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼:
1 NSDate *now = [NSDate date]; 2 NSCalendar *calendar = [NSCalendar currentCalendar]; 3 4 //獲取年、月、日、時、分、秒等組件 5 NSDateComponents *dateComponents = [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond fromDate:now]; 6 NSLog(@"[%d]", dateComponents.year); //年 7 NSLog(@"[%d]", dateComponents.month); //月 8 NSLog(@"[%d]", dateComponents.day); //日 9 NSLog(@"[%d]", dateComponents.hour); //時 10 NSLog(@"[%d]", dateComponents.minute); //分 11 NSLog(@"[%d]", dateComponents.second); //秒轉載于:https://www.cnblogs.com/cmembd/p/3855834.html
總結
以上是生活随笔為你收集整理的取得NSDate实例各个字段的数字的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 阿里资深系统架构师九峰谈云计算
- 下一篇: 清职院学城网