Skip to content

Instantly share code, notes, and snippets.

@jameskrauser
Last active January 5, 2018 05:52
Show Gist options
  • Select an option

  • Save jameskrauser/fe9883920420b134847c8ae6c982d907 to your computer and use it in GitHub Desktop.

Select an option

Save jameskrauser/fe9883920420b134847c8ae6c982d907 to your computer and use it in GitHub Desktop.
Timer [Swift][memo]
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var Label1: UILabel!
@IBOutlet weak var Label2: UILabel!
var timer = Timer()
override func viewDidLoad() {
super.viewDidLoad()
self.updateTimer()
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector( updateTimer ), userInfo: nil, repeats: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@objc func updateTimer(){
let mytimer = DateFormatter()
let mydate = DateFormatter()
mytimer.timeStyle = .short //.full
mydate.timeStyle = .full
Label1.text = mytimer.string(from: NSDate() as Date)
Label2.text = mydate.string(from: NSDate() as Date)
}
@jameskrauser
Copy link
Author

Timer Swift

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment