这个可以根据需要调整 在day month hour minute second 等都行
以下是以当前时间戳为基础,调整时间为明天的零点零时零分零秒 可以根据需要 写成毫秒的
+(NSString *)GetTomorrowDay:(NSDate *)aDate { NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *components = [gregorian components:NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:aDate]; [components setDay:([components day]+1)]; NSDate *beginningOfWeek = [gregorian dateFromComponents:components]; // // // // NSDateFormatter *dateday = [[NSDateFormatter alloc] init]; [dateday setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; [dateday stringFromDate:beginningOfWeek]; DLog(@"%@",[dateday stringFromDate:beginningOfWeek]);//年月日 时分秒 // // // // DLog(@"%@",[NSString stringWithFormat:@"%ld", (long)[beginningOfWeek timeIntervalSince1970]]);//时间戳 return @"";//喜欢用啥 就返回啥吧 }
调用方法 NSLog(@"%@",[self GetTomorrowDay:[NSDate date]]);
时间: 2024-10-06 23:18:57