Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are many thing wrong with this code:</p> <p>Why create all these object:</p> <pre><code>NSString *modiDate = [NSString stringWithFormat:@"1338229800"]; //example time interval value NSNumber *time = [NSNumber numberWithDouble:([modiDate doubleValue] - 3600)]; NSTimeInterval interval = [time doubleValue]; </code></pre> <p>When this is the same:</p> <pre><code> NSString *modiDate = [NSString stringWithFormat:@"1338229800"]; NSTimeInterval interval = [modiDate doubleValue] - 3600; </code></pre> <hr> <p>Here you assing a new date to online:</p> <pre><code>NSDate *online = [NSDate date]; </code></pre> <p>only to set an other date to online here:</p> <pre><code>online = [NSDate dateWithTimeIntervalSince1970:interval]; </code></pre> <p>You should have done this: </p> <pre><code>NSDate *online = [NSDate dateWithTimeIntervalSince1970:interval]; </code></pre> <hr> <p>I'm sure what you problem with this code, but it works correctly. You might want to set the locale, not really need but might have some effect in localization:</p> <pre><code>NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; dateFormatter.locale = [NSLocale systemLocale]; [dateFormatter setDateFormat:@"MM/dd/yyyy HH:mm:ss aaa"]; NSLog(@"result: %@", [dateFormatter stringFromDate:online]); </code></pre> <hr> <p><strong>Added new code from edit</strong></p> <p>In your edit you added this code:</p> <pre><code>NSDate *dateFromString1 = [[NSDate alloc] init]; dateFromString1 = [format dateFromString:modDate]; </code></pre> <p>Here you are leaking an <code>NSDate</code> object,just do this:</p> <pre><code>NSDate *dateFromString1 = [format dateFromString:modDate]; </code></pre> <p>And as state in the answer by <a href="https://stackoverflow.com/users/127493/martin">martin</a> the problem is in the time format string.</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.
    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