を表すdouble値がありNSTimeInterval
ます。double値から正しい日付を作成したいのですが、これが私のコードです。出力を取得していますが、実際の値からいくつかの変更があります。
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]);
ここで何が悪かったのですか?何か案が?
編集:
最初にテストするために、私は日付をに変換し、日付をNSTimeInterval
取り戻そうとしました。コードと出力は次のとおりです。
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]);
出力は次のとおりです。
result: 05/30/2012 12:02:55 PM actual date:5/30/2012 2:02:55 PM