gpt4 book ai didi

iphone - 如何从 NSDate 中减去小时数?

转载 作者:太空狗 更新时间:2023-10-30 03:09:42 24 4
gpt4 key购买 nike

我想从约会中减去 4 小时。我使用以下代码将日期字符串读入 NSDate 对象:

NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSDate * mydate = [dateFormatter dateFromString:[dict objectForKey:@"published"]];

接下来我该做什么?

最佳答案

NSDate *newDate = [theDate dateByAddingTimeInterval:-3600*4];

Link to documentation .


NSDate *newDate = [[[NSDate alloc] initWithTimeInterval:-3600*4
sinceDate:theDate]] autorelease];

Link to documentation .

关于iphone - 如何从 NSDate 中减去小时数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1160977/

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