在这里,我想使用 swift 3 xcode 使用某些特定城市(如America/Mexico_City)的时区获取当前的小时/分钟/秒/毫秒。我试图获得墨西哥城的当前时间-小时/分钟/秒/毫秒,例如,
let date = Date()
var calendar = Calendar.current
calendar.timeZone = TimeZone.init(identifier: "America/Mexico_City")! /* Something wrong here */
hrOfDay = calendar.component(.hour, from: date)
curMin = calendar.component(.minute, from: date)
curSec = calendar.component(.second, from: date)
curMillSec = Int(Int64(Date().timeIntervalSince1970 * 1000)) /* this should be fetched using calendar object */
print("hours = \(hrOfDay):\(curMin):\(curSec):\(curMillSec)")
但我无法获得像墨西哥城这样的特定城市的当前时间。所以,请帮帮我。