oc之获取系统当前时间的方法

 

int main(int argc, const char * argv[]) {

 

    @autoreleasepool {

 

        

 

        NSDate* date = [NSDate date];

 

        NSLog(@"%@",date);

 

        NSLog(@"%@",[date descriptionWithLocale:[NSLocale currentLocale]]);

 

        

 

        //NSDate和NSString转换

 

        NSDateFormatter* formattor = [[NSDateFormatter alloc]init];

 

        formattor.dateFormat=@"yyyy-MM-dd hh:mm:ss";

 

        NSString* str = [formattor stringFromDate:date];

 

        NSLog(@"%@",str);

 

        //获取年月日

 

        NSCalendarDate* calender = [NSCalendarDate calendarDate];

 

        NSInteger year = [calender yearOfCommonEra];

 

        NSLog(@"%ld",year);

 

      

 

        

 

    }

 

    return 0;

 

}

 

 

原文地址:https://www.cnblogs.com/xzz5211314/p/5121032.html