1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
//获取当前时间
NSDate *now = [NSDate date];
NSLog(@ "now date is: %@" , now);
NSCalendar *calendar = [NSCalendar currentCalendar];
NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |
NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit |
NSSecondCalendarUnit;
NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
int year = [dateComponent year];
int month = [dateComponent month];
int day = [dateComponent day];
int hour = [dateComponent hour];
int minute = [dateComponent minute];
int second = [dateComponent second];
NSLog(@ "year is: %d" , year);
NSLog(@ "month is: %d" , month);
NSLog(@ "day is: %d" , day);
NSLog(@ "hour is: %d" , hour);
NSLog(@ "minute is: %d" , minute);
NSLog(@ "second is: %d" , second);
http://my.oschina.net/notting/blog/83267
|
iOS-获取当前时间的年、月、日、时、分、秒
最新推荐文章于 2023-09-02 08:47:01 发布