bootstrap datepicker,beforeShowDay和禁用日期数组 [英] bootstrap datepicker, beforeShowDay and array of disabled dates

查看:677
本文介绍了bootstrap datepicker,beforeShowDay和禁用日期数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用bootstrap datepicker插件( https://github.com/ eternicode / bootstrap-datepicker / blob / release / docs / index.rst ),其中包含禁用日期数组。

I am trying to use bootstrap datepicker plugin (https://github.com/eternicode/bootstrap-datepicker/blob/release/docs/index.rst) with array of disabled days passed into it.

我的代码(部分):

 var disabled_dates = ["23.03.2014","21.03.2014"];
 $("#datepicker").datepicker({
      language: "pl",
      autoclose: true,
      startDate: '+1d',
      weekStart: 1,
      default: 'dd.mm.yyyy',
      beforeShowDay: function(date){
           var formattedDate = $.fn.datepicker.DPGlobal.formatDate(date, 'dd.mm.yyyy', 'pl');
           if ($.inArray(formattedDate.toString(), disabled_dates) != -1){
               return {
                  enabled : false
               };
           }
          return;
      }
  });

它工作(几乎)OK。它禁用日期错误。而不是禁用23.03.2014它禁用24.04.2014。
我不知道问题在哪里,时区可能?任何建议?

it works (almost) OK. It disables wrong date. Instead of disabling 23.03.2014 it disabled 24.04.2014. I am not sure where is the issue, on timezone maybe? Any suggestions?

推荐答案

在插件内部,我发现了 $。fn.datepicker.DPGlobal。 formatDate 返回UTC格式的字符串,而不是GMT。尝试将 formattedDate 变量的设置更改为:

Looking inside the plugin, I found out $.fn.datepicker.DPGlobal.formatDate returns a UTC-formatted string instead of GMT. Try changing the setting of formattedDate variable to this:

var formattedDate = date.toLocaleDateString('pl',{day:'2-digit',year:'numeric',month:'2-digit'});

这篇关于bootstrap datepicker,beforeShowDay和禁用日期数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆