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

Ios 从时区获取当前时间,而不是系统/移动时间,ios,swift,timezone,nsdate,Ios,Swift,Timezone,Nsdate,有人能帮我得到时区的当前时间吗 例如,如果用户有一个带有移动设备的印度时区,即下午5点,但他静态地将移动时间更改为下午5点30分,那么这里我需要的是实际的时区时间,而不是用户根据其偏好更改的移动时间。如果您需要访问世界时钟,请联系NTP服务器。去Cocoapods找一个豆荚来做。以下示例适用于: 这可能是你正在寻找的复制品。 class ViewController: UIViewController { let netAssociation = NetAssociation(serve

有人能帮我得到时区的当前时间吗


例如,如果用户有一个带有移动设备的印度时区,即下午5点,但他静态地将移动时间更改为下午5点30分,那么这里我需要的是实际的时区时间,而不是用户根据其偏好更改的移动时间。

如果您需要访问世界时钟,请联系NTP服务器。去Cocoapods找一个豆荚来做。以下示例适用于:

这可能是你正在寻找的复制品。
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)
    }
}