gpt4 book ai didi

objective-c - dateByAddingTimeInterval 参数语法

转载 作者:搜寻专家 更新时间:2023-10-30 20:06:16 25 4
gpt4 key购买 nike

如果我将方法 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

这很奇怪,因为第三个日期应该是 2012-08-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

使输出正确?

谢谢。

最佳答案

NSDate 以秒计算时间。

关于objective-c - dateByAddingTimeInterval 参数语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12189014/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com