import UIKit
class TimeDateController: UIViewController {
@IBOutlet weak var timeLabel: UILabel!
@IBOutlet weak var dateLabel: UILabel!
var timer = Timer()
override func viewDidLoad() {
super.viewDidLoad()
updateTimer()
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true)
// Do any additional setup after loading the view.
}
@objc func updateTimer(){
let timeFormatter = DateFormatter()
let dateFormatter = DateFormatter()
timeFormatter.timeStyle = .medium
dateFormatter.dateStyle = .medium
timeLabel.text = timeFormatter.string(from: NSDate() as Date)
dateLabel.text = dateFormatter.string(from: NSDate() as Date)
}
}
Sign up here with your email
ConversionConversion EmoticonEmoticon