2016-07-29 57 views
-1

任何人都可以帮助我获取时区的当前时间吗?从时区获取当前时间,而不是系统/移动时间

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

+0

的可能的复制[iOS的如何检测用户已经改变了的系统时间,如果没有比较服务器时间设备时间](http://stackoverflow.com/questions/32457797/ ios-how-to-detect-user-has-change-system-time-and-if-not-compare-device-time-w) – Westside

+0

This [gist](https://gist.github.com/krishashok/) 8002711)可能是你正在寻找的。 – sketchyTech

回答

1

如果您需要访问世界时钟,请联系NTP服务器。去Cocoapods找一个容器来做到这一点。下面的例子是为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) 
    } 
} 
相关问题