1

I want to get diff seconds between NSDate. I used [NSDate timeIntervalSinceDate] methods, but it returns always zero. Below is my code.

NSLog(@"sent date : %@", message.sentDate);
NSLog(@"prev: %@", _previousShownSentDate);
NSLog(@"%d", [message.sentDate timeIntervalSinceDate:_previousShownSentDate]);

In here, message.sentDate, _repviousShownSentDate are NSDate object.

But In logs, the difference seconds are always zero.

[1363:907] sent date : 2013-05-16 01:36:22 +0000
[1363:907] prev: 2013-05-16 01:36:17 +0000
[1363:907] 0
[1363:907] sent date : 2013-05-16 01:36:25 +0000
[1363:907] prev: 2013-05-16 01:36:17 +0000
[1363:907] 0

The third log line must be 5 (01:36:22 and 01:36:17). but it is zero.

I don't understand what i do mistake.

4

1 回答 1

2

因为 " %d" 是一个整数,而 " timeIntervalSinceDate:" 返回的值是一个 double (NSTimeInterval)。

%4.2f在第三行“”中使用“ ” NSLog

于 2013-05-18T13:33:36.880 回答