我想在 iPhone SDK 中获取 2 个日期和日期之间的时差。
问问题
446 次
2 回答
0
试试这个更新
NSString *strDatehere = @"22/11/2012 11:12:00 PM";
NSDateFormatter *heredateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[heredateFormatter setDateFormat:@"dd/MM/yyyy hh:mm:ss a"]; // set date formate with your dates
NSDate *datehere = [heredateFormatter dateFromString: strDatehere];
NSTimeInterval timeDifference = [[NSDate date] timeIntervalSinceDate:datehere];
double minutes = timeDifference / 60;
double hours = minutes / 60;
double seconds = timeDifference;
double days = minutes / 1440;
NSLog(@"%.0f, %.0f, %.0f, %.0f", days, hours, minutes, seconds);
于 2012-11-26T05:18:36.963 回答
0
我通常以秒为单位找出差异并计算 ceil(diffInSeconds/86400)。
还关注作品
NSDate *endDate=[dateFormat dateFromString:now];
NSTimeInterval interval = [YourDate timeIntervalSinceDate:endDate];
int diff=interval/86400;//for converting seconds into days.
于 2012-11-26T05:30:53.743 回答