例如,如果我选择时间:下午3点和小时数:5小时,那么得到(晚上8点)作为答案"
答案 0 :(得分:2)
let calendar = Calendar.current
let date = calendar.date(byAdding: .hour, value: 5, to: Date())
or
let date = calendar.date(byAdding: . minute, value: 330, to: Date())
现在你可以得到一小时
let comp = calendar.dateComponents([.hour, .minute], from: date)
let hour = comp.hour
let minute = comp.minute
print(hour)// This is your answer.