I'm running a piece of code that returns nil
when running on an iPhone with a different language setting. An example in code looks like this:
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMM d, yyyy, h:mm a"
let thisDate = "Mar 4, 2017, 7:50 PM"
let foundationDate = dateFormatter.string(from: Foundation.Date())
print("As String - thisDate: \(thisDate), foundationDate: \(foundationDate)")
print("As Date - thisDate: \(dateFormatter.date(from: thisDate)), foundationDate: \(dateFormatter.date(from: foundationDate))")
If I run this, I get:
As String - thisDate: Mar 4, 2017, 7:50 PM, foundationDate: okt. 22, 2017, 7:57 PM
As Date - thisDate: nil, foundationDate: Optional(2017-10-22 17:57:00 +0000)
Can anyone show how to override the client settings so thisDate
won't return nil?