Getting current time from timezone, not the system/mobile time

前端 未结 1 1183
陌清茗
陌清茗 2021-01-27 17:18

Can any one help me to get the current time of the time zone?

Say for example if the user has an Indian timezone with mobile i.e. 5.00 PM, but he statically change his m

相关标签:
1条回答
  • 2021-01-27 17:45

    If you need access to the world's clock, contact an NTP server. Go to Cocoapods and find a pod to do that. The example below is for 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)
        }
    }
    
    0 讨论(0)
提交回复
热议问题