我需要在每次循环运行时将NSDATE增加一天。我需要将该日期存储在核心data.can中。有人告诉我如何做到这一点吗?日期应该存储在nsdictionary中,所有内容都应该存储在nsdictionary中
发布于 2011-10-31 02:40:02
BPDeveloper的解决方案可以工作,除非在相关的夏令时转换期间。例如,如果您在任何美国时区,并且currentDate是2011年11月6日上午12:30,那么由于夏令时的转换,将该时间加上24小时实际上是2011年11月6日晚上11:30。
这里有一个可以避免这个问题的替代解决方案:
NSDate *currentDate = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
[offsetComponents setDay:1];
NSDate *nextDate = [gregorian dateByAddingComponents:offsetComponents toDate: yourDate options:0];发布于 2011-07-16 04:44:47
你可以使用类似这样的东西:
NSDate *currentDate = [NSDate date]; // This could of course be whatever date you want.
NSDate *newDate = [[currentDate] dateByAddingTimeInterval:3600 * 24];https://stackoverflow.com/questions/6712807
复制相似问题