日期数后的特定日期 [英] Specific date after number of dates
本文介绍了日期数后的特定日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前我正在研究 NSDate
和 NSDateFormatter
.
Currently I'm working on NSDate
and NSDateFormatter
.
我的问题是我需要找到用户指定日期的 100 天后的日期
.
目前我正在使用这个硬编码的字符串来查找未来的日期.
Currently I'm using this hard-coded string for finding a future date.
calendar.maximumDate = [self.dateFormatter dateFromString:@"20/08/2015"];
但这不是正确的方法,也不适用于用户指定的日期.有没有办法做到这一点?
But it is not correct way and not work with user specified date. Is there anyway to achieve this ?
请帮帮我.
提前致谢.
推荐答案
像这样:
// How much day to add
int addDaysCount = 100;
// Create and initialize date component instance
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
[dateComponents setDay:addDaysCount];
// Retrieve date with increased days count
NSDate *newDate = [[NSCalendar currentCalendar]
dateByAddingComponents:dateComponents
toDate:fromdateHere options:0];
这篇关于日期数后的特定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文