Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

format a NSDate to DDMMYYYY?

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

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

gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

dateComponents = [[NSDateComponents alloc] init];
self.date = [gregorian dateByAddingComponents:dateComponents toDate:[NSDate date] options:0];

Do I have to use the [dateComponents day] and so on? is there some method that can help me to performing that task like in PHP?

like image 766
clement Avatar asked Dec 03 '22 02:12

clement


1 Answers

Try this

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"ddMMyyyy"];
NSString *textDate = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:[NSDate date]]];
NSLog(@"Date %@",textDate);
[dateFormatter release];
like image 141
visakh7 Avatar answered Dec 18 '22 09:12

visakh7