-1

i use this code to get informations from strings with this format "01-05-2011"

NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
    [formatter setDateFormat:@"dd'-'MM'-'yyyy"];
    // Your date represented as a NSDate
    NSDate *dateDepart = [formatter dateFromString:daparatureFly.date];
NSDateComponents *comps = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit
                                                              fromDate:dateDepart];

Then when i take the month like this [comps day],[comps month] , i have 1 and 5 , i want to have 01, 05 . Any one can help me ? thanx

user761812
  • 245
  • 2
  • 5
  • 15
  • Please reward the people who have helped you in the past and [accept some answers](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work). Thanks. – DarkDust May 24 '11 at 13:38
  • @DarkDust i alwayse accept answers ! why you tell me this – user761812 May 24 '11 at 13:49
  • Because with this question including, you have accepted answers to two of your ten questions. And a number of your questions have valid answers that could be accepted: [1](http://stackoverflow.com/questions/6073855/how-to-add-description-to-the-uitableview), [2](http://stackoverflow.com/questions/6075696/how-to-make-a-rotate-animation), [3](http://stackoverflow.com/questions/6066309/put-attribute-of-one-object-in-differents-rows). – DarkDust May 24 '11 at 14:06

2 Answers2

2

Those components are NSSintegers, they are not formatted. When you use it in string you can do as follows:

NSString *day = [NSString stringWithFormat:@"%02d", [comps day]];
MByD
  • 135,866
  • 28
  • 264
  • 277
0

Something akin to...

//UNTESTED
[NSString stringWithFormat:@"%02d", [comps day]];
Damo
  • 12,840
  • 3
  • 51
  • 62