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;

}

 

posted @ 2016-01-08 09:17  33sve  阅读(384)  评论(0编辑  收藏  举报