jQuery datepicker displaying a Buddhist date

2019-06-03 10:49发布

Is there any jQuery datepicker plugin to display as Buddhist date?

Currently I use the jQuery UI datepicker to display it, but it's not actually I want. Here is the code:

$(document).ready( function() {
    $("#datepicker").datepicker( {
        appendText: ' yyyy-mm-dd',
        autoSize: true,
        buttonImage: 'images/calendar.gif',
        buttonImageOnly: true,
        changeMonth: true,
        changeYear: true,
        dateFormat: 'yy-mm-dd',
        showOtherMonths: true,
        selectOtherMonths: true,
        showOn: 'both',
        onSelect: function(dateText, inst) {
            year = dateText.substring(0, 4);
            month = dateText.substring(5, 7);
            day = dateText.substring(8);
            _year = parseInt(year) + 543 + '';
            $(this).val(_year + '-' + month + '-' + day);
        },
        beforeShow: function(input, inst) {
            year = input.value.substring(0, 4);
            month = input.value.substring(5, 7);
            day = input.value.substring(8);
            _year = parseInt(year) - 543 + '';
            $(this).datepicker("setDate", new Date(_year, month - 1, day, 0, 0, 0, 0));
        }
    });
});

What I want is when #datepicker has no value, the calendar pop up is displaying the current date + 543 years. When #datepicker has a value, the calendar pop up is displaying the date in the #datepicker value.

The problem is when the selected year is a leap year, for example, 2008-02-29 AD is valid but we can't display 2551-02-29 (Buddhist date) (which is the same date) on that pop up.

Update 2010-07-30

According to Add support for Thai year format in datepicker module and Datepicker: Support non-Gregorian calendars it seems they plan to create support for non-Gregorian calendars.

Currently I try to use the plugin jQuery Calendars by Keith Wood.

2条回答
叛逆
2楼-- · 2019-06-03 11:37

I've created plugins for jQuery UI datepicker to make it support the Buddhist Era format. More details in jQuery UI datepicker extension for the Buddhist era

查看更多
冷血范
3楼-- · 2019-06-03 11:50

You can find my modified version of jQuery DatePicker here:

http://www.anassirk.com/articles/1

The blog is in Thai so I'll briefly explain it below:

Download the plugin here: http://www.anassirk.com/files/DatePicker.zip

The usage is quite similar to the standard jQuery DatePicker with one extra boolean option named "isBuddhist" which you can set it to true to render the Buddhist calendar.

$("#datepicker-th").datepicker({ dateFormat: 'dd/mm/yy', isBuddhist: true, defaultDate: toDay }); 

important: in Buddhist mode you have to set the "defaultDate" option to a date string of the format specified in the "dateFormat" option. Like '19/3/2554' for 'dd/mm/yy'

Cheers!

查看更多
登录 后发表回答