这是我的代码:
变量:
let date = Date()
let calendar = Calendar.current
let hour = calendar.component(.hour, from:date)
let minute = calendar.component(.minute, from:date)
let second = calendar.component(.second, from:date)
然后我将其显示在标签中:
time.text = "\(hour):\(minute):\(second)"
它显示为19:1,不确定是24小时还是UTC或其他。
首先,如何让它显示:19:01,第二,如何显示它是12小时的时间,所以7:01?
提前致谢!
答案 0 :(得分:0)
var formatter: DateFormatter = {
var tmpFormatter = DateFormatter()
tmpFormatter.dateFormat = "dd-MM-YYYY hh:mm a"
return tmpFormatter
}()
func getDate() {
let date = Date()
print(formatter..string(from: date))
}