format a NSDate to DDMMYYYY?

China☆狼群 提交于 2019-12-01 06:39:07

Try this

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"ddMMyyyy"];
NSString *textDate = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:[NSDate date]]];
NSLog(@"Date %@",textDate);
[dateFormatter release];
Ruben Marin

Just:

  NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
  [outputFormatter setDateFormat:@"ddMMyyyy"];
  NSString *textDate = [NSString stringWithFormat:@"%@",[outputFormatter stringFromDate:[NSDate date]]];
  [outputFormatter release];

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]
senthilMuthu
    NSDate *date=[NSDate date];
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"ddMMyyyy"];
    NSString *dateOfGame =[formatter stringFromDate:date];
    [formatter release];

Try this:

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];

[dateFormatter setDateFormat:@"ddMMyyyy"];

NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]);

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!