从时区获取当前时间,而不是系统/移动时间

任何人都可以帮助我获得时区的当前时间?

举个例子,如果用户有一个印度时区的移动,即下午5点,但他静态地改变他的移动时间到下午5时30分,在这里我需要实际的时区时间,而不是用户改变他的偏好的移动时间。

如果您需要访问世界时钟,请联系NTP服务器。 去Cocoapods并find一个吊舱来做到这一点。 下面的例子是针对ios-ntp的 :

class ViewController: UIViewController { let netAssociation = NetAssociation(serverName: "time.apple.com") func viewDidLoad() { super.viewDidLoad() netAssociation.delegate = self netAssociation.sendTimeQuery() } func reportFromDelegate() { let timeOffset = netAssociation.offset // serverTime will always be in UTC. Use an NSDateFormatter // to display it in your local timezone let serverTime = NSDate(timeIntervalSince1970: timeOffset) } }