本文介绍了如何向 NSDate 添加 1 天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上,正如标题所说.我想知道如何为 NSDate 添加 1 天.
Basically, as the title says. I'm wondering how I could add 1 day to an NSDate.
如果是这样:
21st February 2011它会变成:
22nd February 2011或者如果是:
31st December 2011它会变成:
1st January 2012. 推荐答案Swift 5.0 :
var dayComponent = DateComponents() dayComponent.day = 1 // For removing one day (yesterday): -1 let theCalendar = Calendar.current let nextDate = theCalendar.date(byAdding: dayComponent, to: Date()) print("nextDate : (nextDate)")目标 C:
NSDateComponents *dayComponent = [[NSDateComponents alloc] init]; dayComponent.day = 1; NSCalendar *theCalendar = [NSCalendar currentCalendar]; NSDate *nextDate = [theCalendar dateByAddingComponents:dayComponent toDate:[NSDate date] options:0]; NSLog(@"nextDate: %@ ...", nextDate);这应该是不言自明的.
更多推荐
如何向 NSDate 添加 1 天?
发布评论