Change language for bootstrap DateTimePicker

前端 未结 11 1633
长发绾君心
长发绾君心 2020-12-03 04:15

I use bootstrap-datetimepicker.js Copyright 2012 by Stefan Petre

http://www.malot.fr/bootstrap-datetimepicker/index.php

I import the js and anot

相关标签:
11条回答
  • 2020-12-03 04:54

    Just include your desired locale after the plugin. You can find it in locales folder on github https://github.com/uxsolutions/bootstrap-datepicker/tree/master/dist/locales

    <script src="bootstrap-datepicker.XX.js" charset="UTF-8"></script>
    

    and then add option

    $('.datepicker').datepicker({
       language: 'XX'
    });
    

    Where XX is your desired locale like ru

    0 讨论(0)
  • 2020-12-03 04:57

    1.you will use different locale array element in datepicker.js from following link https://github.com/smalot/bootstrap-datetimepicker/tree/master/js/locales

    2.add array in datepicker.js like this:

    $.fn.datepicker.Constructor = Datepicker;
        var dates = $.fn.datepicker.dates = {
            en: {
                days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
                daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
                daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
                months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
                monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
                today: "Today"
            },
            CN:{
            days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
            daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
        daysMin: ["日", "一", "二", "三", "四", "五", "六", "日"],
        months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
        monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
        today: "今天",
        suffix: [],
        meridiem: ["上午", "下午"]
    }
    	};

    0 讨论(0)
  • 2020-12-03 04:58

    The option is locale: 'ru'

    But first, you have to call the script ../moment.js/version/locale/ru.js

    Hope this helps.

    0 讨论(0)
  • 2020-12-03 05:05

    Try this:

    $( ".form_datetime" ).datepicker( $.datepicker.regional[ "zh-CN" ], { dateFormat: 'dd.mm.yyyy hh:ii' });
    
    0 讨论(0)
  • 2020-12-03 05:06

    1.First add this js file to your HTML.

    <script th:src="@{${webLinkFactory.jsLibRootPath()}+'/bootstrap-datepicker.nl.min.js'}" charset="UTF-8"type="text/javascript"></script>
    

    obviously after moment.min.js.

    content of bootstrap-datepicker.nl.min.js will be

    ;(function($){
        $.fn.datepicker.dates['nl'] = {
            days: ["Zondag", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"],
            daysShort: ["Zon", "Man", "Din", "Woe", "Don", "Vri", "Zat", "Zon"],
            daysMin: ["Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za", "Zo"],
            months: ["Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"],
            monthsShort: ["Jan", "Feb", "Mrt", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"],
            today: "Vandaag",
            suffix: [],
            meridiem: []
        };
        $.fn.datetimepicker.dates['nl'] = {
            days: ["Zondag", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"],
            daysShort: ["Zon", "Man", "Din", "Woe", "Don", "Vri", "Zat", "Zon"],
            daysMin: ["Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za", "Zo"],
            months: ["Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"],
            monthsShort: ["Jan", "Feb", "Mrt", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"],
            today: "Vandaag",
            suffix: [],
            meridiem: []
        };
    }(jQuery));
    

    2.set this line in the ready function of your js file.

    $(document).ready(function () {
        $.fn.datetimepicker.defaults.language = 'nl';
    }
    

    3.initialize your datetimepicker in this way

    $(this).datetimepicker({
                            format: "yyyy-mm-dd hh:ii",
                            autoclose: true,
                            weekStart: 1,
                            locale: 'nl',
                            language: 'nl'
                        });
    

    following this steps i was able to convert my english datepicker and datetimepicker to dutch successfully.

    0 讨论(0)
  • 2020-12-03 05:07

    i think you have to set it in the options:

    $(".form_datetime").datetimepicker({
        isRTL: false,
        format: 'dd.mm.yyyy hh:ii',
        autoclose:true,
        language: 'ru'
    });
    

    if its not working, be sure that:

    $.fn.datetimepicker.dates['en'] = {
        days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
        daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
        daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
        months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
        monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
        today: "Today"
    };
    

    is defined for 'ru'

    0 讨论(0)
提交回复
热议问题