閱讀885 返回首頁    go 阿裏雲 go 技術社區[雲棲]


iOS-獲取當前時間的年、月、日、時、分、秒

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分享網 https://iosshare.cn


最後更新:2017-04-02 15:15:05

  上一篇:go chrome觀看flash視頻卡死的解決辦法
  下一篇:go HDU1028 拆分數母函數