0
當用戶在美國時,爲什麼此代碼在時區返回空白? 在其他國家完美運作。如果在洛杉磯時區爲空
// Get local time zone
let localTimeZoneAbbreviation = TimeZone.current.abbreviation() ?? ""
let indexStartOfText = localTimeZoneAbbreviation.index(localTimeZoneAbbreviation.startIndex, offsetBy: 3) // 3
let timeZone = localTimeZoneAbbreviation.substring(from: indexStartOfText)
print("TimeZone:",timeZone)
我需要導致一些格式:
「-7」 洛杉磯
「-4」 紐約
「+2」 漢堡
等
你爲什麼要解析字符串?使用'TimeZone'的'secondsFromGMT'方法。 – rmaddy
如何從秒中提取我需要的東西並精確到全世界 –
您可以使用DateFormatter並設置'dateFormat =「x」' –