按下按钮时有没有办法将时间记录为字符串? 我不知道从哪里开始?
答案 0 :(得分:4)
只需从该按钮创建IBAction
,如下所示:
@IBAction func buttonPressed(_ sender: UIButton) {
let currentDateTime = Date()
let formatter = DateFormatter()
formatter.timeStyle = .short
formatter.dateStyle = .none
print(formatter.string(from: currentDateTime))
}