0

We are currently showing JavaScript DateTime objects in the current user locale according to their language analog to this example (taken from MDN directly, since this matches our code but is already extracted):

var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
console.log(new Intl.DateTimeFormat().format(date));

In general, this works great. American users get their twisted slashy format 11/20/2012 while German users get their ordered dotty format 20.11.2012. However, this only changes according to the language. The screenshot below shows a system locale setting that is different: English language but German DateTime format. In this case, the JavaScript example sadly shows the English format 11/20/2012.

Since this is confusing some of our users, is there a way to retrieve the current system DateTime format setting or locale in order to render the JavaScript DateTime correctly? All the questions I found so far on Stackoverflow only concentrated on the user language and not the user system DateTime format setting.

System setting with English language but German date format

ingofreyer
  • 1,086
  • 15
  • 27
  • Arguably that's a misbehaviour of the browser. You as the website owner should not/can not worry about all the possible ways in which the preferred locale can be set on any individual computer. – deceze Dec 06 '17 at 09:14
  • I completely agree with that Still, it would be great to find a way to work around this issue or at least document it for future StackOverflow users – ingofreyer Dec 06 '17 at 09:22

1 Answers1

0

After more thorough research it became apparent that this is - as of right now - really impossible. This StackOverflow answer contains an alternative way to render the date. Both the way presented in my question and the answer are depending on the correct implementation of the browser. All other options to resolve the problem would require the user to select a custom DateTime format and us to render the date accordingly. This would be possible using the locale argument of DateTimeFormat as described in MDN.

ingofreyer
  • 1,086
  • 15
  • 27