【发布时间】:2014-08-10 21:17:20
【问题描述】:
我们如何使用日期名称(星期一和星期日之间)获取当前一周中特定日期的日期?例如我想知道这个星期天的日期是什么,或者上星期一的日期是什么。
编辑:这里我是如何借助 @juniperi 的链接解决问题的
//To get current day
CFAbsoluteTime at = CFAbsoluteTimeGetCurrent();
CFTimeZoneRef tz = CFTimeZoneCopySystem();
SInt32 currentWeekdayNumber = CFAbsoluteTimeGetDayOfWeek(at, tz);
//We are adding or substracting from the day we want and add to the current date
NSDate *now = [NSDate date];
int daysToAdd = theDayNumberWeWant - currentWeekdayNumber;
NSDate *newDate1 = [now dateByAddingTimeInterval:60*60*24*daysToAdd];
【问题讨论】:
标签: ios objective-c xcode nsdate