如何从NSDate中减去小时数? [英] How does one subtract hours from an NSDate?
本文介绍了如何从NSDate中减去小时数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从约会中减去4个小时。我将日期字符串读入NSDate对象使用以下代码:
I would like to subtract 4 hours from a date. I read the date string into an NSDate object use the following code:
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];
文档链接。
NSDate *newDate = [[[NSDate alloc] initWithTimeInterval:-3600*4
sinceDate:theDate]] autorelease];
文档链接。
这篇关于如何从NSDate中减去小时数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文