-2

だから私は次のコードを持っています:

 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"MM/dd/yyyy hh:mma"];
    NSString *dateString = [dateFormat stringFromDate:self.firstUsed];
 NSLog(@"FIRST USED %@ %f", dateString, [[NSDate date] timeIntervalSinceDate:self.firstUsed]);

FIRST USED 06/15/2012 10:42PM 716.087895

私を混乱させるのは、173.755023 を入力しても、2012 年 6 月 15 日の 10:42 に戻らないことです。これはどのように可能ですか?正しい番号は 1339714440 だと思います

4

2 に答える 2

0

これを試して :

NSDate* referenceDate = [NSDate dateWithTimeIntervalSince1970: 0];
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"GMT"];
int offset = [timeZone secondsFromGMTForDate: referenceDate];
int unix_timestamp =  [curdate timeIntervalSince1970];
int Timestamp = unix_timestamp - offset;
于 2012-06-16T11:21:09.977 に答える
-2

次のコードを書き留めてください:

NSDateFormatter *dtFormatAppointment = [[NSDateFormatter alloc] init];

[dtFormatAppointment setDateFormat:@"MM/dd/yyyy hh:mm a"];

NSString *dateString = [dateFormat stringFromDate:self.firstUsed];

NSTimeInterval time = [dateString timeIntervalSince1970];

NSLog(@"FIRST USED %@ %.f", dateString, time);

このコードはあなたのために働いています。

于 2012-06-16T06:59:07.997 に答える