iOS版Menampilkan Waktu Secara实时
[Artikel di edit lagi kapan-kapan]
帕凯Timer
var timer = Timer()
buat属性ti dateFormatter
自然属性视图DidLoad
dateFormatter = DateFormatter()
dateFormatter?.dateStyle = .medium
dateFormatter?.timeStyle = .medium
dateFormatter?.dateFormat =“ hh-mm-ss a”
PERHATIKAN dateFormat“ hh — mm — ss a”
viewDidLoad()
覆盖viewDidLoad(){
timer = Timer.scheduledTimer(timeInterval:1,target:self,选择器:#selector(printDateRealTime),userInfo:nil,重复:true)
}
printDateRealTime()
让一个= dateFormatter?.string(from:Date())
打印(一个!)
塔拉!