|
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];intyear
= [dateComponent year];intmonth
= [dateComponent month];intday
= [dateComponent day];inthour
= [dateComponent hour];intminute
= [dateComponent minute];intsecond
= [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 发布
本文演示如何在代码中获取当前时间,并使用NSCalendar解析为年、月、日、小时、分钟、秒等详细日期组件。
2万+

被折叠的 条评论
为什么被折叠?



