format a NSDate to DDMMYYYY?

前端 未结 7 494
面向向阳花
面向向阳花 2021-01-13 18:12

I have to send a DDMMYYY date from a Date to communicate with an API.

NSDateComponents *dateComponents; NSCalendar *gregorian; NSDate *date;

gregoria         


        
7条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-13 18:16

    Agree With Ruben Esposito

    Just change your code like this.

    NSDateFormatter *dtFormatter = [[NSDateFormatter alloc]init];
    [dtFormatter setDateFormat:@"ddMMyyyy"];    
    NSString *strDate = [NSString stringWithFormat:@"%@",[dtFormatter stringFromDate:[NSDate date]]];
    [dtFormatter release];
    NSLog(@"%@",strDate);
    

提交回复
热议问题