iOS Dev (55) 获得本年度、月、日本和其他信息

iOS Dev (55) 获得本年度、月、日本和其他信息

-

NSDate *now = [NSDate date];
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];

Reference

  • http://www.cnblogs.com/programmer-blog/p/3265110.html
posted @ 2015-12-11 09:39  zfyouxi  阅读(134)  评论(0编辑  收藏  举报