4

I am not sure, if we can achieve this. However, I would like to know if there is a way we can find what is pattern of date based on locale.

What I am trying to achieve is placeholder text inside datepicker? Depending on locale, my function should figure out date pattern for that locale.

For example, when navigator.language is "en-us" date pattern is mm/dd/yyyy.
if navigator.language is "fr" date pattern should be "dd/mm/yyyy"

Reading MDN docs about Intl.DateTimeFormat, I can pretty much get pattern using following code:

console.log(new Intl.DateTimeFormat(navigator.language).resolved.pattern) // M/d/y for "en-us"

but the above code won't give me mm/dd/yyyy or I was not able to find any docs that can help me get that.

Any suggestion?

Thanks
Viral

Viral
  • 310
  • 3
  • 19
  • http://stackoverflow.com/questions/2388115/get-locale-short-date-format-using-javascript this may help you. – owaism Jan 15 '15 at 20:05
  • Which datepicker are you using? Some datapickers such as jQuery UI's have built in [locale support](http://jqueryui.com/datepicker/#localization)... – War10ck Jan 15 '15 at 20:06
  • owaism... in the "2388115/" solution the format are hardcoded.. I am trying to see can I achieve that without hard-coding format..
    War10ck this is custom dateTimepicker..
    – Viral Jan 15 '15 at 20:50
  • This seems like a strange way to achieve localization. It isn't hard to get the date format by reverse engineering a date string for a known date. But to get the corresponding UI text would take a bit more. Take French, for example. Their date format is d/M/yyyy, but in French that would be j/m/aaaa. No matter how you get the date format, I don't know how you expect to translate it to appropriate UI text. – gilly3 Jan 16 '15 at 01:29
  • @gilly3 I agree it would be very tricky.. I was just curious to see. if we can get format by reverse engineering :) – Viral Jan 21 '15 at 00:05

0 Answers0