I'm trying to get the current date in this format "YYYY MM DD" by doing the following:
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en")
formatter.dateFormat = "yyyy MM dd"
formatter.timeZone = TimeZone.current
let stringDate = formatter.string(from: Date()) //1
let currentDate = formatter.date(from: stringDate)! //2
1- lets assume that today's date is 2018 03 30 in this case stringDate = "2018 03 30" which is fine.
2- here it returns nil even though that I have used the same formatter that converted the current date to this format.
now I tried the code on playground i got the same results as the following screenshot:
what am I doing wrong ??