Knockout Daterangepicker 正确的日期格式
Knockout Daterangepicker correct moment formatting of date
我正在尝试使用日期选择器:https://sensortower.github.io/daterangepicker 有一个带剔除功能的日期选择器。
没问题,但我还希望选择器本身的自定义日期字段为 "DD-MM-YYY"(而不是当前的 "DD/MM/YYYY"
我的模板定义是:
<input type="text" readonly class="form-control"
data-bind=" daterangepicker: dateRange,
daterangepickerOptions: {
maxDate: [moment().add(20,'years')],
ranges: {
'Komende maand': [moment(), moment().add(1,'month')],
'Komende week': [moment(), moment().add(1,'week')],
'Altijd': 'all-time',
'Aangepast:': 'custom'
},
periods: ['day'],
locale: 'nl',
timeZone: null
},
daterangepickerFormat: 'DD-MM-YYYY'," />
因此在选择器本身中它会显示要更改的当前日期,但这些日期仍然是 "en" 格式。
您确定支持 nl
区域设置标志吗?将其替换为:
locale: { inputFormat: 'DD-MM-YYYY' },
并且标签发生变化。
解释:
我试图找出是哪个库的源代码呈现了您要更改的标签。结果发现正在使用一个名为 inputFormat
的设置,它应该存储在 locale
对象中。
以下是如何将默认设置应用于此对象:
Config.prototype._locale = function(val) {
return $.extend({
applyButtonTitle: 'Apply',
cancelButtonTitle: 'Cancel',
inputFormat: 'L',
startLabel: 'Sart',
endLabel: 'End'
}, val || {});
};
您看到 "L"
值被用作默认格式,这导致 DD/MM/YYYY
字符串。使用字符串(模板中的"nl"
)扩展对象对我来说意义不大,所以我猜你必须创建自己的设置对象。您可以根据 moment.js' 区域设置计算它。
(一个代码笔,我在其中拼凑了一个文件,其中包含您正在使用的所有库并表明我的建议有效:http://codepen.io/anon/pen/xEWJKd)
我正在尝试使用日期选择器:https://sensortower.github.io/daterangepicker 有一个带剔除功能的日期选择器。
没问题,但我还希望选择器本身的自定义日期字段为 "DD-MM-YYY"(而不是当前的 "DD/MM/YYYY"
我的模板定义是:
<input type="text" readonly class="form-control"
data-bind=" daterangepicker: dateRange,
daterangepickerOptions: {
maxDate: [moment().add(20,'years')],
ranges: {
'Komende maand': [moment(), moment().add(1,'month')],
'Komende week': [moment(), moment().add(1,'week')],
'Altijd': 'all-time',
'Aangepast:': 'custom'
},
periods: ['day'],
locale: 'nl',
timeZone: null
},
daterangepickerFormat: 'DD-MM-YYYY'," />
因此在选择器本身中它会显示要更改的当前日期,但这些日期仍然是 "en" 格式。
您确定支持 nl
区域设置标志吗?将其替换为:
locale: { inputFormat: 'DD-MM-YYYY' },
并且标签发生变化。
解释:
我试图找出是哪个库的源代码呈现了您要更改的标签。结果发现正在使用一个名为 inputFormat
的设置,它应该存储在 locale
对象中。
以下是如何将默认设置应用于此对象:
Config.prototype._locale = function(val) {
return $.extend({
applyButtonTitle: 'Apply',
cancelButtonTitle: 'Cancel',
inputFormat: 'L',
startLabel: 'Sart',
endLabel: 'End'
}, val || {});
};
您看到 "L"
值被用作默认格式,这导致 DD/MM/YYYY
字符串。使用字符串(模板中的"nl"
)扩展对象对我来说意义不大,所以我猜你必须创建自己的设置对象。您可以根据 moment.js' 区域设置计算它。
(一个代码笔,我在其中拼凑了一个文件,其中包含您正在使用的所有库并表明我的建议有效:http://codepen.io/anon/pen/xEWJKd)