0
我正在開發一個聊天應用程序。我想確定UTC時區和設備當前時區之間的時差。如何在swift3中做到這一點?快速查看utc時區和設備時區之間的區別
我正在開發一個聊天應用程序。我想確定UTC時區和設備當前時區之間的時差。如何在swift3中做到這一點?快速查看utc時區和設備時區之間的區別
// Returns a Date initialized to the current date and time
let currentDate = Date()
// Returns the time zone currently used by the system
let timeZone = NSTimeZone.system
// Returns the difference in seconds between the receiver and Greenwich Mean Time at a given date.
let timeZoneOffset = timeZone.secondsFromGMT(for: currentDate)/3600
print(timeZoneOffset, "hours offset for timezone", timeZone)
// example output for Denver (considers daylight saving time)
// -6 hours offset for timezone America/Denver (current)