iOS-获取当前时间

         NSDate *currentDate = [NSDate date];//获取当前时间,日期
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"YYYY-MM-dd"];
        NSString *dateString = [dateFormatter stringFromDate:currentDate];
        NSLog(@"dateString:%@",dateString);
        
        UILabel *timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 110 + self.picWhith + 30, WIDTH, 20)];
        timeLabel.text = dateString;
        timeLabel.textAlignment = NSTextAlignmentCenter;
        timeLabel.font = [UIFont systemFontOfSize:16];
        timeLabel.textColor = WHITECOLOR;
        [self.view addSubview:timeLabel];

你可能感兴趣的:(iOS-获取当前时间)