Two solutions:
- Add
en_US_POSIX
locale for a fixed format. -
Use
ISO8601DateFormatter
(iOS 8+), the benefit is no locale, no date format, no time zone.func toDate() -> Date? { let dateFormatter = ISO8601DateFormatter() return dateFormatter.date(from: self) }
In any case return an optional, fatalError()
in production environment causes pretty bad user experience.