Note that there are some explanatory texts on larger screens.

plurals
  1. PONSDate conversion issue in iOs
    primarykey
    data
    text
    <p>I am having a double value that represents a <code>NSTimeInterval</code>. I want to create the correct date from the double value, here is my code. I am getting the output, but there is some changes from the actual value.</p> <pre><code>NSString *modiDate = [NSString stringWithFormat:@"1338229800"]; //example time interval value NSNumber *time = [NSNumber numberWithDouble:([modiDate doubleValue] - 3600)]; NSTimeInterval interval = [time doubleValue]; NSDate *online = [NSDate date]; online = [NSDate dateWithTimeIntervalSince1970:interval]; NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"MM/dd/yyyy HH:mm:ss aaa"]; NSLog(@"result: %@", [dateFormatter stringFromDate:online]); </code></pre> <p>What went wrong here? Any idea?</p> <p><strong>EDIT:</strong> For testing first i converted a date to <code>NSTimeInterval</code> and tried to get back the date. Here is the code and output.</p> <pre><code>NSString *modDate = [NSString stringWithFormat:@"5/30/2012 2:02:55 PM"]; NSDateFormatter *format = [[NSDateFormatter alloc]init]; [format setDateFormat:@"MM/dd/yyyy HH:mm:ss aaa"]; NSDate *dateFromString1 = [[NSDate alloc] init]; dateFromString1 = [format dateFromString:modDate]; [format release]; NSTimeInterval timeInterval1 = [dateFromString1 timeIntervalSince1970]; NSLog(@"timeinterval : %f",timeInterval1); NSDate *online = [NSDate date]; online = [NSDate dateWithTimeIntervalSince1970:timeInterval1]; NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"MM/dd/yyyy HH:mm:ss aaa"]; NSLog(@"result: %@", [dateFormatter stringFromDate:online]); </code></pre> <p>and the output is:</p> <pre><code> result: 05/30/2012 12:02:55 PM actual date:5/30/2012 2:02:55 PM </code></pre>
    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.
 

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