Localization of jQuery datapicker using globalize plugin

Is it possible to localize jQuery datapicker using the globalize plugin ( https://github.com/jquery/globalize )?

I tried this way

// get a date format var dt = Globalize.culture().calendar.patterns.d; $('#dp1').datepicker({ dateFormat : dt }); 

but it does not work, because the datepicker and globalize plugin use two different formats.

I need a date with two digits per month, 2 digits per day and 4 digits per year, so in jquery the date format should be "dd / mm / yy". But globalization uses a different date format: ru-Us → M / d / yyyy it-IT → dd / MM / yyyy

+4
source share
3 answers

Small Converter:

 Globalize.getPatternForDatapicker = function (pattern) { return this.culture().calendar.patterns[pattern || 'd'].toLowerCase().replace('yyyy', 'yy'); }; 

and

 $('#dp1').datepicker({dateFormat : Globalize.getPatternForDatapicker()}); 
+5
source

In the early days of globalization (then called jQuery globalization), the Datepicker version was specifically fixed .
Honestly, I do not think it is more useful, but you can try to apply the same modifications to the current version, and the problem will be solved. This can be done quite simply with the diff command, available on many Unix-like systems (for example, on Windows via Cygwin).


Edit: API

I think it is at least useful to mention that Datepicker offers a rich API .
You can use Datepicker Localization to configure. However, when it comes to the date format, I am afraid that you will be forced to use some kind of replacement to remove the "excessive" y from the year field. This is something I would rather not do, instead I would install Datepicker as suggested earlier, but ...

+1
source

I ran into many problems with these two format inconsistencies. Finally, jQuery guys answered me that they would switch to globalization format. However, when ...: (

0
source

Source: https://habr.com/ru/post/1433806/


All Articles