-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 回答