Search code examples
jqueryinternationalizationmomentjsanytime

Any+Time: i18N of day and month abbreviations from moment.js


I'm using the time / date picker Any+Time (jQuery-Plug-In). Additionally moment.js for time manipulation. Instead of moment.js the Any+Time plug-in does not support different languages directly.

For moment.js there additional files to support other languages including the abbreviations of months and days. So I want them to reuse.


Solution

  • After setting the language globally in moment.js:

    <script type="text/javascript" src="js/lib/moment.min.de.js"></script>
    <script>
         moment.lang("de");
    </script>
    

    I an instance of an moment object to gather the abbreviations while initializing the datepicker:

    <script>
        var $moment = moment();
        $('.datepicker').AnyTime_picker({ 
            format: "%a %d.%m.%Y",
            dayAbbreviations: $moment.lang()._weekdaysShort,
            monthAbbreviations: $moment.lang()._monthsShort
        })
    </script>