get current date from [NSDate date] but set the time to 10:00 am

前端 未结 5 925
小鲜肉
小鲜肉 2020-12-01 02:17

How can I reset the current date retrieved from [NSDate date] but then change the time to 10:00 in the morning.

5条回答
  •  庸人自扰
    2020-12-01 03:04

    NSDate *currentDate = [NSDate date];
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    [comps setHour:10];
    NSDate *date = [gregorian dateByAddingComponents:comps toDate:currentDate  options:0];
    [comps release];
    

    Not tested in xcode though :)

提交回复
热议问题