format a NSDate to DDMMYYYY?

前端 未结 7 489
面向向阳花
面向向阳花 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:29

    Try this:

    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    
    [dateFormatter setDateFormat:@"ddMMyyyy"];
    
    NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]);
    

提交回复
热议问题