我正在嘗試爲iOS創建一個鬧鐘應用程序,我是Swift新手。我想知道如何從UIDatePicker獲取時間。到現在爲止,我有一個代碼,只是給出了整個日期和時間。 `進口的UIKitSwift3-如何只從UIDatePicker獲得時間
類的ViewController:UIViewController的{
@IBOutlet weak var alarmTime: UIDatePicker!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func alarmTime(_ sender: UIDatePicker){
sender.datePickerMode = UIDatePickerMode.time
print(sender.date)
}
} ` Here is the screenshot of the output of the above code in the terminal
顯示你試過代碼,顯示這個**有這只是給你需要將你格式化整個日期與時間** –
代碼dateformatter。 – KKRocks
@ Anbu.Karthik這是我的日期選取器的IBAction函數。現在我只是簡單地打印設定的時間。 '@IBAction FUNC alarmTime(_發件人:的UIDatePicker){// = alarmTime.datePickerMode UIDatePickerMode.time 打印(alarmTime.date) } ' –