Open InzeNL opened 6 days ago
The .toLocaleDateString()
doesn't seem to work correctly either. For me, it formats it to 24 hour, with my PC at the following configuration:
Browser settings has language set to "English: Canada"
@wou007 Could you describe the configuration your PC has, with the details I mentioned in my last message? It'll make it easier for me to reproduce
My Firefox browser is configured to set the localization to English (Netherlands) from my OS config. In Edge the localization is 24h clock as expected.
I get mixed results myself. I tested it with this application and this fiddle: https://jsfiddle.net/3d8jotxa/
var date = new Date(2000, 11, 31, 15, 14, 13);
var dateTimeString = date.toLocaleString();
var dateString = date.toLocaleDateString();
var timeString = date.toLocaleTimeString();
document.getElementById("date-time").textContent = dateTimeString;
document.getElementById("date").textContent = dateString;
document.getElementById("time").textContent = timeString;
Firefox:
Edge:
Chrome:
Firefox seems to be the one that is consistent. In my case, it is also the one that is correct both time
Maybe it's best to make this a setting, 12 hour or 24. Also add an option to switch between am and pm
Making this a task to add a settings menu, in which 12/24/AM/PM can be selected
Currently, the timestamp is shown using the format as defined by the user's locale. However, this might differ from the time format of the user's device. For example: The language could be en-US, but the time format can be 24h-format. For this reason, we should instead find a way to obtain the preferred time format, as opposed to the preferred locale.