I am converting date to day, but if I just println() the current selected date in the datepicker, I get wrong time and wrong date.
@IBOutlet weak var datepicker: UIDatePicker!
@IBAction func displayDay(sender: AnyObject) {
var chosenDate = self.datepicker.date
println(chosenDate)
I've following date selected date.
And click on the button underneath datepicker. I get following line in output
2015-01-11 20:17:37 +0000
Can somebody tell me.what's wrong with output?
This is fine because the date picker uses its local time but it stores UTC time. It means your local time offset is -5h. You can do as follow to extract the right date and time from it:
Swift 3 or later
Swift 3.0 - If You want to get a result in date format then use the following code.
Use this method to get correct date: