2017-04-10 72 views

回答

2
// 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)