We have an android app which more or less constists of only a webview, displaying a webapp. At some point, we want to display some timestamp to the user and use the following code
let dateString = new Date().toLocaleTimeString();
The problem is, this always produces a 12h time representation (ie with AM/PM, for instance 3:15 PM
instead of 15:15
), even if we set the device to use 24h clock (and the device does respect this setting, because we see the correct time in the statusbar). We also set the device to use German language and removed the english language settings. No luck either. The device locale is used, as our app is shown in the correct language, but the timestrings are still wrong.
window.navigator.language -> "de-AT"
new Date().toLocaleTimeString(); -> "6:10:13 PM"
new Date().toLocaleTimeString(window.navigator.language); -> "18:10:32"
At a first glance, the last line seemed as a possible workaround, but if language is for instance "en-US" this will always return 12h format, regardless whether the os is configured for using 24h clock or not.
I'm aware of this question, which seems somehow related to this issue, but the answers don't work for us.
Using various virtual devices I found out, it still works correctly on chrome 58 (on API 26) but does not work any more on chrome 61 (on API 27). Currently testing at chrome 70 beta, the problem still persists.
It's also important to note, that it works correctly in chrome itself (ie if I display a time stamp in a test website, it uses the system settings), but only fails in the webview.
Our current workaround is to generate timestamps via native app, but that seems rather clumsy.
UPDATE
I know I can do some things on the webapp side like overriding toLocaleTimeString
(which in fact, I already did to get the correct format from the native app).
My question is more about: Is there any known changed behaviour (and maybe a setting to reverse this) in the native WebView
which causes this issue to happen, because this works/worked like a charm on devices with Chrome <= 58.
In the meantime I filed an issue with chromium, they were able to reproduce it. Maybe this will get fixed in one of the next versions ...
UPDATE 2
The issue is already fixed on google's side and may be rolled out with some future update. In the meantime I will continue to use my current override of toLocaleTimeString()
which calls back to the native app ...