Open matejhacin opened 2 years ago
@matejhacin Try parsing dateA with .toDate("yyyy-MM-dd'T'hh:mm:ss", region: Region.ISO) !
I faced this problem but was able to fix it by setting the Locale of the Region to "en_US_POSIX". You can read more about why this works here
Hello, I am parsing dates in my app using this library and I've just noticed an issue when my device is in 12-Hour Time mode.
The API I am working with can return dates in two different formats:
Format A: 2021-12-06T00:00:00
Format B: 2020-06-10T06:00:00.785+02:00
Parsing
Format B
always works whether device is in 12-Hour or 24-Hour mode.Parsing
Format A
however, will fail if the device is in 12-Hour mode. It does work in 24-Hour mode.I am currently using a temporary workaround, by providing my own formatter and Region when using the
toDate()
extension. Like this:"2020-06-10T06:00:00".toDate() // Fails in 12-Hour Time mode
"2020-06-10T06:00:00".toDate("yyyy-MM-dd'T'hh:mm:ss", region: Region.UTC) // Works both in 12-Hour and 24-Hour mode