来自按钮的时间戳?

Dan*_*ode 0 time button swift

有没有办法在按下按钮时将时间记录为字符串?我不知道从哪里开始?

小智 5

只需IBAction像这样从该按钮创建:

@IBAction func buttonPressed(_ sender: UIButton) {
    let currentDateTime = Date()
    let formatter = DateFormatter()
    formatter.timeStyle = .short    
    formatter.dateStyle = .none
    print(formatter.string(from: currentDateTime))
}
Run Code Online (Sandbox Code Playgroud)