如果我说upcoming monday
那我怎么能得到日期upcoming monday
?
就像,今天Thu, 04-04-2013
比我怎么知道即将到来的日期wednesday
?
希望我能够澄清你。
这里问了类似的问题,但我无法理解:
如果我说upcoming monday
那我怎么能得到日期upcoming monday
?
就像,今天Thu, 04-04-2013
比我怎么知道即将到来的日期wednesday
?
希望我能够澄清你。
这里问了类似的问题,但我无法理解:
NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *date = [NSDate date];
NSDateComponents *weekdayComponents = [gregorian components:NSWeekdayCalendarUnit fromDate:date];
NSInteger todayWeekday = [weekdayComponents weekday];
enum Weeks {
SUNDAY = 1,
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY
};
NSInteger moveDays=WEDNESDAY-todayWeekday;
if (moveDays<=0) {
moveDays+=7;
}
NSDateComponents *components = [NSDateComponents new];
components.day=moveDays;
NSCalendar *calendar=[[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
NSDate* newDate = [calendar dateByAddingComponents:components toDate:date options:0];
NSLog(@"%@",newDate);
只是为了激怒Anoop;):
NSDate* now = [NSDate date];
NSTimeInterval nowInterval = [now timeIntervalSince1970];
int days = (int)(nowInterval / (24 * 60 * 60));
int today = (days + 4) % 7;
NSDate* saturday = [NSDate dateWithTimeIntervalSince1970:nowInterval + (6 - today) * 24 * 60 * 60];
NSLog(@"saturday = %@", saturday);