获得当前年、月、日

来源:互联网 发布:淘宝的详情页免费模板 编辑:程序博客网 时间:2024/04/29 20:17
//获取当前时间  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];    int year = [dateComponent year];    int month = [dateComponent month];    int day = [dateComponent day];    int hour = [dateComponent hour];    int minute = [dateComponent minute];    int second = [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);
0 0
原创粉丝点击