我认为标题说明了一切。 我可以得到当前时间,但我需要当前时间+ 1小时。
NSDate *today = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd MMM YYYY hh:mm"];
NSString *dateString = [dateFormat stringFromDate:today];
myUILabel.text = dateString;
如何格式化日期以便将当前时间加1小时?
答案 0 :(得分:3)
NSDate *dateAfter_1hour = [NSDate dateWithTimeInterval:60*60 sinceDate:[NSDate date]];
UIDatePicker *datepicker = [[UIDatePicker alloc]init];
[datepicker setDate:dateAfter_1hour animated:YES];
答案 1 :(得分:2)
在斯威夫特:
theDateAnHourFromNow = NSDate().dateByAddingTimeInterval(3600)