iOS 获取时间
2015-09-24 12:41
549 查看
01 //获取当前时间
02 NSDate *now = [NSDate date];
03 NSLog(@”now date is: %@”, now);
04
05 NSCalendar *calendar = [NSCalendar currentCalendar];
06 NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
07 NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
08
09 int year = [dateComponent year];
10 int month = [dateComponent month];
11 int day = [dateComponent day];
12 int hour = [dateComponent hour];
13 int minute = [dateComponent minute];
14 int second = [dateComponent second];
15
16 NSLog(@”year is: %d”, year);
17 NSLog(@”month is: %d”, month);
18 NSLog(@”day is: %d”, day);
19 NSLog(@”hour is: %d”, hour);
20 NSLog(@”minute is: %d”, minute);
21 NSLog(@”second is: %d”, second);
转自iOS分享网 http://iosshare.cn
02 NSDate *now = [NSDate date];
03 NSLog(@”now date is: %@”, now);
04
05 NSCalendar *calendar = [NSCalendar currentCalendar];
06 NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
07 NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
08
09 int year = [dateComponent year];
10 int month = [dateComponent month];
11 int day = [dateComponent day];
12 int hour = [dateComponent hour];
13 int minute = [dateComponent minute];
14 int second = [dateComponent second];
15
16 NSLog(@”year is: %d”, year);
17 NSLog(@”month is: %d”, month);
18 NSLog(@”day is: %d”, day);
19 NSLog(@”hour is: %d”, hour);
20 NSLog(@”minute is: %d”, minute);
21 NSLog(@”second is: %d”, second);
转自iOS分享网 http://iosshare.cn
相关文章推荐
- iOS 9 适配
- iOS实现截屏并保存到相册
- ionic preparing for ios 9
- 单例模式浅析 - ios
- ios9下ionic框架报[$rootScope:infdig] 10 $digest() iterations reached. Aborting!的解决办法
- IOS视图生命周期与视图控制器关系
- iOS控件TextView添加placeholder属性的两种方法
- ios- 归档 解档
- iOS 根据字体设置size
- ios 归档接档
- iOS 系统自带定位
- iOS开发——多线程
- iOS多线程学习---NSOperation
- iOS 开发 屏幕尺寸 --------开发者必备
- iOS tintColor与backgroundColor
- iOS详细讲解沙盒机制
- [ZZ]研究所工作,想转iOS开发,求指点
- IOS中NSTimeZone小结
- iOS---XCode7 + IOS9 问题及解决方案
- IOS绘制渐变背景色折线图的一种尝试