Note that there are some explanatory texts on larger screens.

plurals
  1. POissue in Changing date formate
    primarykey
    data
    text
    <p>i have one array of string something like below </p> <pre><code>newlymadeArray( "03/05/2013", "09/22/2013", "03/02/2013", "03/02/2013", "08/22/2013", "11/02/2013", "07/08/2013", "08/31/2013", "05/13/2013", "07/11/2013", "10/07/2013", "02/20/2013" </code></pre> <p>)</p> <p>current formate is MM/dd/yyyy</p> <p>i want to change it to dd/MM/yyyy</p> <p>i am using following code for this </p> <pre><code> NSLog(@"_newlymadeArray%@",_newlymadeArray); //logic for changing date formate for( int i=0; i&lt;_newlymadeArray.count; i++){ NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init]; [dateFormatter1 setDateFormat:@"MM/dd/yyyy"]; NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init]; [dateFormatter2 setDateFormat:@"dd/MM/yyyy"]; NSDate *old = [dateFormatter1 dateFromString:[_newlymadeArray objectAtIndex:i]]; NSLog(@"old %@",old); NSString *old1 =[dateFormatter1 stringFromDate:old]; NSDate *new = [dateFormatter2 dateFromString:old1]; NSLog(@"new %@",new); NSString *string = [dateFormatter2 stringFromDate:new]; NSLog(@"string %@",string); [_convertedBdates addObject:string]; } NSLog(@"_convertedBdates%@",_convertedBdates); </code></pre> <p>this is what im getting as output </p> <pre><code> old 2013-03-04 18:30:00 +0000 new 2013-05-02 18:30:00 +0000 string 03/05/2013 old 2013-09-21 18:30:00 +0000 new (null) string (null) ] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil' *** First throw call stack: </code></pre> <p>my questions are why old get printed 2013-03-04 instead of 05/03/2013 at the end of first time loop it gets printed 03/05/2013 instead of 05/03/2013 and when loop is running second time it gets null value in new so thats why adding null value in array program get crashed </p> <p>plz tell me what im doing wrong ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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