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

iOS Dev (55) 获取当前年、月、日等信息,布布扣,bubuko.com

iOS Dev (55) 获取当前年、月、日等信息

上一篇:iOS Dev (53) 修复UIImagePickerController偷换StatusBar颜色的问题


下一篇:android中Activity回传数据