【发布时间】:2018-02-15 12:32:08
【问题描述】:
我想根据我正在使用昨天给我的代码的 iPhone 设备获取当前时间。 我的代码是
let calendar = Calendar.current
let dateStart = calendar.startOfDay(for: Date())
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "hh:mm a"
dateFormatter.timeZone = TimeZone.current
let strDate = Date().description(with: Locale.current) //dateFormatter.string(from: dateStart)
print("日期开始 ***** (dateStart)")
我收到了回复:
开始日期 ***** 2018-02-14 18:30:00 +0000
谁能帮助我今天的正确时间是 15-02-2018 18:00
谢谢
【问题讨论】:
-
你从 print Date () 得到了什么?
-
使用:
Date().description(with: Locale(identifier: NSTimeZone.local.identifier)) -
感谢您的回答,但我该如何使用呢?你能分享一个例子吗?
-
为什么会有downvote?
标签: ios swift nsdateformatter nstimezone