DateFormatter doesn't Works

Hi! I don't know why, but the date from formatter is nil.

let date1 = "22/05/1977"
let date2 = "01/06/1975"
let date3 = "26/05/1974"
let formatter = DateFormatter()
formatter.dateFormat = "dd/MM/yyyy"
let d1 = formatter.date(from: data1)
let d2 = formatter.date(from: data2)
let d3 = formatter.date(from: data3)

why d1, d2 and d3 will be nil ?


There are many things that can go wrong here, including:
Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
I fixed.
So, is very strange, by default format.calendar is ".gregorian" and it's doesn't works.
If I assign format.calendar = Calendar(idenfier: .gregorian) and works :)


I fixed.

No you didn’t. Well, you fixed this specific problem but you have not fixed the problem in general.

The fundamental problem here is that the Gregorian calendar can be customised by your locale. For example, if you’re in the US, which defaults to 12-hour time, and you force the system to use 24-hour time (in System Preferences > Language & Region > General), you end up with a slightly tweaked Gregorian calendar. If you want to avoid this sort of thing, you should set the locale to en_US_POSIX. It’s specifically designed to work with non-localised values.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
DateFormatter doesn't Works
 
 
Q