我正在尝试使用datetimepicker,我有这些函数来覆盖日期格式。在其他地方,我们使用momentjs进行日期时间格式化。
Date.parseDate = function (input, format) {
return moment(input, format).toDate();
};
Date.prototype.dateFormat = function (format) {
return moment(this).format(format);
};
使用datetimepicker的momentjs格式:
format: "DD/MM/YYYY H:mm:ss",
formatTime: 'H:mm',
formatDate: 'DD/MM/YYYY',
但是当使用片刻时,"突出显示的日子"功能不起作用。
如何制作"突出显示日期"功能是否有效?
答案 0 :(得分:0)
找到解决方案:
$(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"
]
});
There is working plunker example
主要问题是我的情况是browserify / gulp模块连接..而且datetimepicker在jquery下是未定义的......
因此尝试将构建更改为WebPack ....