本文介绍了xdan/datetimepicker使用"momenjs"而是默认使用"php-date-formatter" -“重要日子";功能不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用datetimepicker,并且我具有这些功能来覆盖日期格式.在其他地方,我们使用momentjs进行日期时间格式化.

I am trying to use datetimepicker and I have these functions to override date formatting. In other places we use momentjs for date time formatting.

这是我的小例子..

Date.parseDate = function (input, format) {
    return moment(input, format).toDate();
};
Date.prototype.dateFormat = function (format) {
    return moment(this).format(format);
};

将momentjs格式用于datetimepicker:

Use momentjs formats for datetimepicker:

format: "DD/MM/YYYY H:mm:ss",
formatTime: 'H:mm',
formatDate: 'DD/MM/YYYY',

但是当使用瞬间时,突出显示的日子"功能不起作用.

But when using moment the "highlighted days" function does not work.

如何使突出显示的日子"功能正常工作?

推荐答案

找到的解决方案:

$(document).ready(function() {

  var myFormatter = {
    parseDate: function(vDate, vFormat) {
      return moment(vDate, vFormat).toDate();
    },
    guessDate: function(vDateStr, vFormat){
      return moment(vDateStr, vFormat).toDate();
    },
    parseFormat: function(vChar, vDate){
      return vDate; // date string (I guess)

    },
    formatDate: function(vChar, vDate) {
      return moment(vChar).format(vDate);
    },

  };

  jQuery.datetimepicker.**setDateFormatter**(myFormatter);


  jQuery('#datetimepicker').datetimepicker({
    timepicker: true,

    // 'd/m/y'format is requared for datetimepicker days HIGHLIGHT function to work!!!
    //Date, time formating: http://php.net/manual/en/function.date.php
    step: 15,
    /*
    // momentJs formating
     format: "d/m/Y H:i:s",
    formatTime: "H:i",
    formatDate: "d/m/Y",
    */

    format: "DD/MM/YYYY H:mm:ss",
    formatTime: 'H:mm',
    formatDate: 'DD/MM/YYYY', //I need to use this format, but it works only when using "d/m/Y" - so somewhere the php date formater is still used..

    highlightedDates: [
      "01/09/2016,,xdsoft_highlighted_mint",
      "02/09/2016,,xdsoft_highlighted_mint",
      "03/09/2016,,xdsoft_highlighted_mint",
      "06.09/2016",
      "07.09.2016",
      "08.09.2016",
      "12.09.2016,Christmas Eve,xdsoft_highlighted_mint",
      "13.09.2016,Christmas Day,xdsoft_highlighted_mint",
      "14.09.2016,Christmas Day,xdsoft_highlighted_mint",
      "26.09.2016,,xdsoft_highlighted_mint"
    ]
  });

有一个有用的插件示例

主要问题是我的情况是browserify/gulp模块串联..而datetimepicker在jquery下未定义...

The main issues are is my case is browserify/gulp modules concatenation.. And that datetimepicker is undefined under jquery...

因此,尝试将构建方式更改为WebPack....

So trying to change building to WebPack....

这篇关于xdan/datetimepicker使用"momenjs"而是默认使用"php-date-formatter" -“重要日子";功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 03:09