format a NSDate to DDMMYYYY?

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

    check the iphonetips,stackoverflow,apple reference

    0 讨论(0)
  • 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);
    
    0 讨论(0)
  • 2021-01-13 18:29

    Just:

      NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
      [outputFormatter setDateFormat:@"ddMMyyyy"];
      NSString *textDate = [NSString stringWithFormat:@"%@",[outputFormatter stringFromDate:[NSDate date]]];
      [outputFormatter release];
    
    0 讨论(0)
  • 2021-01-13 18:29

    Try this:

    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    
    [dateFormatter setDateFormat:@"ddMMyyyy"];
    
    NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]);
    
    0 讨论(0)
  • 2021-01-13 18:32

    Try this

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"ddMMyyyy"];
    NSString *textDate = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:[NSDate date]]];
    NSLog(@"Date %@",textDate);
    [dateFormatter release];
    
    0 讨论(0)
  • 2021-01-13 18:34

    Try this code:

    NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]];
    [dateFormatter setDateFormat:@"ddMMyyyy"];
    NSDate *current = [NSDate date];
    NSString *currentstring = [dateFormatter stringFromDate:current]
    
    0 讨论(0)
提交回复
热议问题