mardi 5 juillet 2016

Swift converting string to Date [duplicate]


This question already has an answer here:

I am having a lot of trouble converting a string to a date. See code below.

let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM-dd-YYYY"
let s = dateFormatter.dateFromString("07-12-1991")

when I print s I see this in the console 1990-12-23 05:00:00 +0000. But this is wrong the date should be July 12th 1991. Ideally it would print out something like 07-12-1991. Where is 1990-12-23 coming from? In addition when I change the date I enter into dateFromString and print out the date I still see 1990-12-23.


Aucun commentaire:

Enregistrer un commentaire