automatic DateTimeFormat based on users language
Im trying to get DatePicker to automatically use the format of the language of the user. I'm developing a chrome plugin, so I can use navigator.language which for me returns 'nl' and
new Intl.DateTimeFormat(navigator.language).format returns a function, but this does not work.
Any advice how I can get this work?
Can't you just the an Intl polyfill? We have an example on the doc DatePicker source code.
Yes, I think the best way to achieve this is to use Intl.
Take a look at the docs http://www.material-ui.com/#/components/date-picker or this example https://github.com/callemall/material-ui/issues/2409#issuecomment-162868427
You will need to add the polyfill:https://github.com/andyearnshaw/Intl.js/
No don't need the polyfill, as it's chrome only.
Found the solution though. I coulnd't put together how to use Intl.DteTimeFormat together with the dateFormat property before, but I figured it out now (and ofcourse its quite simple). Tnx for the help
formatDate(date)
{
return new Intl.DateTimeFormat(navigator.language).format(date);
}
...
<DatePicker dateFormat={this.formatDate.bind(this} ... />