Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is <em>never</em> going to be appropriate:</p> <pre><code>NSString *old1 =[dateFormatter1 stringFromDate:old]; NSDate *new = [dateFormatter2 dateFromString:old1]; </code></pre> <p>You're saying, "Format a date using one formatter... and then parse it using a different one."</p> <p>You've already parsed the value which was in the old format. You now need to <em>format</em> it in the new formatter.</p> <p>I'm not an Objective-C developer, but I suspect you just want:</p> <pre><code>NSDate *date = [dateFormatter1 dateFromString:[_newlymadeArray objectAtIndex:i]]; NSString *string = [dateFormatter2 stringFromDate:date]; [_convertedBdates addObject:string]; </code></pre> <p>Note how there's only <em>one</em> date involved, but two strings (the original format and the new format).</p> <p>Also note that there's no need to create a new pair of formatters on each iteration of the loop. Create them <em>before</em> the loop and reuse them:</p> <pre><code>NSDateFormatter *oldFormatter = [[NSDateFormatter alloc] init]; [oldFormatter setDateFormat:@"MM/dd/yyyy"]; NSDateFormatter *newFormatter = [[NSDateFormatter alloc] init]; [newFormatter setDateFormat:@"dd/MM/yyyy"]; for (int i = 0; i &lt; _newlymadeArray.count; i++) { NSDate *date = [oldFormatter dateFromString:[_newlymadeArray objectAtIndex:i]]; NSString *string = [newFormatter stringFromDate:date]; [_convertedBdates addObject:string]; } </code></pre> <p>(You may <em>also</em> want to check whether <code>date</code> is null within the loop, to handle bad data, of course.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload