3

メソッド dateByAddingTimeInterval: を NSDate に送信すると、次のようになります。

NSDate *today = [NSDate date]; 
NSDate *tomorrow = [now dateByAddingTimeInterval:24.0];
NSDate *yesterday = [now dateByAddingTimeInterval:-24.0];

NSArray *dates = [NSArray arrayWithObjects: today, tomorrow, yesterday, nil];

NSLog(@"today's date is %@", [dates objectAtIndex:0]);
NSLog(@"yesterday's date was %@", [dates objectAtIndex:2]);

私はこの出力を得る:

...The first date is 2012-08-30 02:14:19 +0000
...The third date is 2012-08-30 02:13:55 +0000

3 番目の日付は 2012 年 8 月 29 日だったはずなので、これは奇妙です

しかし... NSDateメッセージを次のように変更すると:

NSDate *today = [NSDate date];
NSDate *tomorrow = [now dateByAddingTimeInterval:24.0 * 60.0 * 60.0];
NSDate *yesterday = [now dateByAddingTimeInterval:-24.0 * 60.0 * 60.0];

* 60.0 を追加すると...

...The first date is 2012-08-30 02:15:25 +0000
...The third date is 2012-08-29 02:15:25 +0000

出力を正しくしますか?

ありがとうございました。

4

1 に答える 1

4

NSDate の秒単位の計算時間。

于 2012-08-30T02:21:25.760 に答える