获取当前的date
NSDate *nowDate = [NSDate date];
使用NSCalendar 计算详细的时间
NSCalendar *calendar = [NSCalendar currentCalendar];
NSUInteger unitFlags = NSYearCalendarUnit | //年
NSMonthCalendarUnit | //月份
NSDayCalendarUnit | //日
NSHourCalendarUnit | //小时
NSMinuteCalendarUnit | //分钟
NSSecondCalendarUnit; // 秒
NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:nowDate];
NSInteger year = [dateComponent year];
NSInteger month = [dateComponent month];
NSInteger day = [dateComponent day];
NSInteger hour = [dateComponent hour];
NSInteger minute = [dateComponent minute];
NSInteger second = [dateComponent second];
网友评论