我已经为 NSDate 和 time 制作了一个 unix 时间戳转换器以进行本机检查。我总是得到日期和时间 1970-01-01 00:00:00 +0000 或 01-01-1970 01:00 返回。我已经用在线转换器检查了时间戳,它很好。时间戳示例:1381350121
我的问题是什么?
代码:
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[[responseData objectForKey:@"expire"] intValue]];
NSDateFormatter *_formatter=[[NSDateFormatter alloc]init];
[_formatter setDateFormat:@"dd-MM-yyyy HH:mm"];
NSString *ExpireSession =[_formatter stringFromDate:date];
NSLog(@"%@ %@", date, ExpireSession);
也试过这个:
NSString * timeStampString = [responseData objectForKey:@"expire"];
NSTimeInterval _interval=[timeStampString doubleValue];
NSDate *date = [NSDate dateWithTimeIntervalSince1970:_interval];
NSDateFormatter *_formatter=[[NSDateFormatter alloc]init];
[_formatter setDateFormat:@"dd-MM-yyyy HH:mm"];
NSString *ExpireSession =[_formatter stringFromDate:date];
NSLog(@"%@ %@", date, ExpireSession);