国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

iOS獲取某個日期后n個月的日期

2019-10-21 18:45:11
字體:
供稿:網(wǎng)友

一、給一個時間,給一個數(shù),正數(shù)是以后n個月,負數(shù)是前n個月;

-(NSDate *)getPriousorLaterDateFromDate:(NSDate *)date withMonth:(NSInteger)month{  NSDateComponents *comps = [[NSDateComponents alloc] init];  [comps setMonth:month];  NSCalendar *calender = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];  NSDate *mDate = [calender dateByAddingComponents:comps toDate:date options:0];  return mDate;}

二、設(shè)置你需要增加或減少的年、月、日即可獲得新的日期,上述的表示獲取mydate日期前一個月的日期,如果該成+1,則是一個月以后的日期,以此類推都可以計算。

- (NSDate *)getLaterDateFromDate:(NSDate *)date withYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day {  NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];  NSDateComponents *comps = nil;  comps = [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:date];  NSDateComponents *adcomps = [[NSDateComponents alloc] init];  [adcomps setYear:year];  [adcomps setMonth:month];  [adcomps setDay:day];  NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:date options:0];  return newdate;}

總結(jié)

以上所述是小編給大家介紹的iOS獲取某個日期后n個月的日期,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對VEVB武林網(wǎng)網(wǎng)站的支持!


注:相關(guān)教程知識閱讀請移步到IOS開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 荆州市| 内江市| 扶沟县| 衡东县| 阿拉善左旗| 溧阳市| 玛沁县| 灌云县| 泽州县| 瑞金市| 武陟县| 丰顺县| 邓州市| 托里县| 诏安县| 栖霞市| 沭阳县| 和林格尔县| 元江| 濮阳县| 佛冈县| 瑞昌市| 关岭| 喀什市| 涟水县| 方正县| 宜丰县| 泗阳县| 襄樊市| 万山特区| 阿拉善左旗| 呼伦贝尔市| 师宗县| 丹棱县| 昌邑市| 永安市| 靖州| 德格县| 社旗县| 霍山县| 兴海县|