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


    NSDate *now = [NSDate date];spa

    NSLog(@"now date is: %@", now);3d

    

    NSCalendar *calendar = [NSCalendar currentCalendar];code

    NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit |        NSMinuteCalendarUnit | NSSecondCalendarUnit;component

    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];orm

    

    NSInteger year = [dateComponent year];it

    NSInteger month = [dateComponent month];class

    NSInteger day = [dateComponent day];date

    NSInteger hour = [dateComponent hour];margin

    NSInteger minute = [dateComponent minute];top

    NSInteger second = [dateComponent second];

    

    NSLog(@"year is: %ld", year);

    NSLog(@"month is: %ld", month);

    NSLog(@"day is: %ld", day);

    NSLog(@"hour is: %ld", hour);

    NSLog(@"minute is: %ld", minute);

    NSLog(@"second is: %ld", second);

相關文章
相關標籤/搜索