In javascript I'm using Date.toLocaleDateString
to format my dates in the user's locale. While in theory it should work, it doesn't.
I am located in the UK. My computer is set to UK and my default language is set to en/gb in both system settings and the browser content settings. Yet, Firefox always displays dates the US format. Is there some trick I'm missing?
The full code for formatting is this:
var timestamp = ...; //some value from ajax call
var dt = new Date(timestamp);
$('#audit-date').text(dt.toLocaleDateString());
In the UK for today's date I would expect to see 05/02/2014
, but I see 02/05/2014
, which is the US version of it.
toLocaleDateString
gives me US style dates. I think it's because we speak English so just download the default en-US version of the browser. I usually write dates in an international way which is unmistakable, for example2014-02-05
for today. – Enounce(new Date()).toLocaleDateString()
give? – VulturinetoLocaleDateString
the US way the other the UK way. I triedtoLocaleDateString(window.navigator.language)
. But it just flips the problem as on the one returning the UK date it returns its language as "en-US" which makes no sense!! what is it based on? – Ibarra