0

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 mobile time to 5.30 PM, here I need the actual timezone time, not the mobile time which the user changed as per his preference.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Abirami Bala
  • 760
  • 1
  • 10
  • 25
  • Possible duplicate of [iOS how to detect user has changed system time, and if not compare device time with server time](http://stackoverflow.com/questions/32457797/ios-how-to-detect-user-has-changed-system-time-and-if-not-compare-device-time-w) – Westside Jul 29 '16 at 13:36
  • This [gist](https://gist.github.com/krishashok/8002711) might be what you are looking for. – sketchyTech Jul 29 '16 at 13:38

1 Answers1

1

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)
    }
}
Code Different
  • 90,614
  • 16
  • 144
  • 163