Current Week Start and End Date

后端 未结 16 1380
轮回少年
轮回少年 2020-11-30 01:56

I want to get the current week start and end date and I also want to use the previous week start and end date and next week of the start and end date in current month.

16条回答
  •  甜味超标
    2020-11-30 02:32

    You can get current day and date by following code:

    NSDate *today = [NSDate date];
        NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
        [dateFormat setDateFormat:@"EEEE"];
        NSString *weekDay = [dateFormat stringFromDate:today];
        [dateFormat setDateFormat:@"dd"];
        NSString *thedate=[dateFormat stringFromDate:today];
        //[dateFormat release];
        NSLog(@"%@ %@", weekDay,thedate);
    

    Now, You need to put some logic in it to calculate starting date and end date of the week. The logic will be such kind,

    if the week day is Monday

    then

    starting date = current date - 0

    end date = current date + 6

    and so on

    I think you can get the idea of it.

提交回复
热议问题