gpt4 book ai didi

swift - 如何计算从选定时间(小时)到给定持续时间的时间(小时)

转载 作者:可可西里 更新时间:2023-11-01 01:12:07 28 4
gpt4 key购买 nike

例如,如果我选择了时间:下午 3 点和小时数:5 小时,则得到 (8pm) 作为答案“

最佳答案

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())

Now you can get hour

let comp = calendar.dateComponents([.hour, .minute], from: date)
let hour = comp.hour
let minute = comp.minute

print(hour)// This is your answer.

关于swift - 如何计算从选定时间(小时)到给定持续时间的时间(小时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46687417/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com