0

(Sorry for my english)

I made a button to get the value of the DatePicker but the hours in the output is 4 hour late than in the DatePicker

My code:

@IBOutlet var date: UIDatePicker!

@IBAction func sauvegarderClicked(sender: AnyObject) {

    println(date.date)
}

Is this the correct way to get the value from the DatePicker ?

And at the end of the output there is a "+0000" how can i remove this?

Clément Bisaillon
  • 5,037
  • 8
  • 32
  • 53
  • possible duplicate of [UIDatePicker return wrong NSDate](http://stackoverflow.com/questions/8356565/uidatepicker-return-wrong-nsdate) – Martin R Aug 29 '14 at 20:25

1 Answers1

2

The date picker gives you the date in GMT.

Take a look at NSDateFormatter which will do what you want.

Gene De Lisa
  • 3,628
  • 1
  • 21
  • 36
  • I did: var date :NSDate = (NSDate.date()); var dateFormater : NSDateFormatter = NSDateFormatter(); dateFormater.dateFormat = "dd:mm:yyyy HH:mm:ss zzz"; But now when i print the date i get: fatal error: unexpectedly found nil while unwrapping an Optional value – Clément Bisaillon Aug 29 '14 at 20:27
  • did you do this?: let s = dateFormater.stringFromDate(date) – Gene De Lisa Aug 29 '14 at 20:42