Reputation: 2309
and first of all thanks in advance. I've been working with iOS/Swift for several years and this is the first time I've seen this strange behaviour. This is the code:
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/MM/yyyy - HH:mm"
let dat = Date()
let formated = dateFormatter.string(from: dat)
CrashlyticsBridge.log("newsresponse date2: \(formated)")
...
I've received 3 crashes from the same user in Fabric with the following log:
+[CrashlyticsBridge log:] line 16 $ newsresponse date2: 23/02/2018 - 77:15 a. m.
The app crashes due to the strange behaviour of the DateFormatter. How can it be possible? HH == 77?
Upvotes: 1
Views: 103
Reputation: 9354
It can be related to Locale
and Calendar
. Set locale
explicitly like:
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
Upvotes: 1