我需要在某個特定時間爲明天設置一個Date對象。我可以想出如何將日期更改爲明天,但不知道如何設置時間。這裏是我的功能:在Swift 3中設置明天的時間
func getTomorrowAt(hour: Int, minutes: Int) -> Date {
let calendar = Calendar.current
var date = calendar.date(byAdding: .day, value: 1, to: Date())
// here I need to set the time to hour:minutes
return date!
}
你可以用'(NS)DateComponents'了點。例如,你可以設置你想要的日期Date()'(now),然後像你一樣添加1天。 – Larme
如何讓DateComponenets獲得今天的日期和特定的時間? – checklist
http://stackoverflow.com/questions/36073704/how-to-change-the-current-days-hours-and-minutes-swift-2 – Larme