gpt4 book ai didi

xcode - Swift:(倒计时应用)如何让日期选择器选择截止日期?

转载 作者:行者123 更新时间:2023-11-30 13:54:13 24 4
gpt4 key购买 nike

制作一个倒计时应用程序,而不是手动添加截止日期,我希望能够使用日期选择器来完成。

这是我现在使用的代码。我需要帮助的是实现代码,让我通过使用日期选择器(竞争日期)来完成此操作。

 // Here we set the current date

let date = NSDate()
let calendar = NSCalendar.currentCalendar()
let components = calendar.components([.Hour, .Minute, .Second, .Nanosecond], fromDate: date)
let hour = components.hour
let minutes = components.minute
let month = components.month
let year = components.year
let day = components.day


let currentDate = calendar.dateFromComponents(components)



// here we set the due date. When the timer is supposed to finish
// final Calendar value

let userCalendar = NSCalendar.currentCalendar()


let competitionDate = NSDateComponents()
competitionDate.year = 2015
competitionDate.month = 6
competitionDate.day = 21
competitionDate.hour = 08
competitionDate.minute = 00
let competitionDay = userCalendar.dateFromComponents(competitionDate)!


// Here we compare the two dates
competitionDay.timeIntervalSinceDate(currentDate!)


let dayCalendarUnit = calendar.components([NSCalendarUnit.Day, NSCalendarUnit.Hour, NSCalendarUnit.Minute], fromDate: date)

最佳答案

您的意思是获取日期选择器的日期?你可以这样做:

let date:NSDate = datePicker.date

关于xcode - Swift:(倒计时应用)如何让日期选择器选择截止日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33857410/

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