javascript jQuery datepicker 显示佛教日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3297652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 00:46:38  来源:igfitidea点击:

jQuery datepicker displaying a Buddhist date

javascriptjqueryjquery-uijquery-pluginsjquery-ui-datepicker

提问by tsurahman

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

是否有任何 jQuery datepicker 插件可以显示为佛教日期?

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

目前我使用jQuery UIdatepicker 来显示它,但它实际上不是我想要的。这是代码:

$(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 #datepickerhas no value, the calendar pop up is displaying the current date + 543 years. When #datepickerhas a value, the calendar pop up is displaying the date in the #datepickervalue.

我想要的是当#datepicker没有价值时,日历弹出显示当前日期 + 543 年。当#datepicker有一个值时,日历弹出窗口显示#datepicker值中的日期。

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.

问题是当所选年份是闰年的时候,例如,2008-02-29广告有效,但我们无法在弹出的情况下显示2551-02-29(佛教日)(这是相同的日期)。

Update 2010-07-30

更新 2010-07-30

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

根据Add support for Thai year format in datepicker moduleand Datepicker: Support non-Gregorian calendars似乎他们计划创建对非公历的支持。

Currently I try to use the plugin jQuery Calendarsby Keith Wood.

目前,我尝试使用插件的jQuery日历基思·伍德

回答by Krissana Rattanapat

You can find my modified version of jQuery DatePicker here:

你可以在这里找到我修改过的 jQuery DatePicker 版本:

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

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

在此处下载插件: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.

用法与标准 jQuery DatePicker 非常相似,带有一个名为“isBuddhist”的额外布尔选项,您可以将其设置为 true 以呈现佛教日历。

$("#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'

重要:在佛教模式下,您必须将“defaultDate”选项设置为“dateFormat”选项中指定格式的日期字符串。像“19/3/2554”表示“dd/mm/yy”

Cheers!

干杯!

回答by sorajate

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

我为 jQuery UI datepicker 创建了插件,使其支持佛教时代格式。佛教时代的jQuery UI日期选择器扩展中的更多细节