-1

I'm trying to create an Alarm, I let the user pick time from Date Picker (from library and Mode: Time). But when I run it on the simulator, The simulator gives me a different time. I will show you code below to see more detail.

@IBOutlet weak var timePicker: UIDatePicker!

I collected time on the simulator screen ( 10:10 AM ) and press button: The local time right now: 2016-05-14 10:10 AM

@IBAction func addTime(sender: UIButton) {

    let time = timePicker.date

    print("Time from picker: \(time)")
    // The result : "Time from picker : 2016-05-14 03:10:39 +0000"
}

The problem right here, That's not correct time. I think some difference between NSDate() and local time right?.

The question: How can I sync them. Or do you have another idea ?

Thanks for your attention

Duong Le
  • 19
  • 2
  • 1
    That date it is correct. You just need to use NSDateFormatter to display local time or a different timezone – Leo Dabus May 14 '16 at 03:53

1 Answers1

0

That output time is indeed correct because it is in GMT FORMAT. Notice that +0000 appended to the time that shows time zone difference between GMT and local time on device. Check the time zone setting on your emulator and set it to match with your local time zone.

Santosh S
  • 1
  • 1