Is there a better way to find midnight tomorrow?

前端 未结 6 2197
天涯浪人
天涯浪人 2021-02-13 22:05

Is there a better way to do this?

-(NSDate *)getMidnightTommorow {
    NSCalendarDate *now = [NSCalendarDate date];
    NSCalendarDate *tomorrow = [now dateByAdd         


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-13 22:34

    NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
    
    NSDate *tomorrow = [NSDate dateWithTimeIntervalSinceNow:(24 * 60 * 60)];
    
    NSDateComponents *components = [gregorian components:(NSYearCalendarUnit |
                                                          NSMonthCalendarUnit |
                                                          NSDayCalendarUnit)
                                                fromDate:tomorrow];
    
    NSDate *midnight = [gregorian dateFromComponents:components];
    

提交回复
热议问题