jquery更改输入字段的日期格式

时间:2016-07-24 10:09:45

标签: jquery html joomla date-format input-field

我遇到了jquery脚本(下面)的问题,该脚本应该更改日期选择器中的日期格式,输入字段(名为'jform [moving_date]')。

var months = ['Jan','Feb','May','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var element = $('input[name=jform[moving_date]]');
element.on('change', function(e) {

// You might need to stop propagation but this will cause other scripts from firing like date picker.
// e.stopPropagation();

var date_parts = $(this).val().split('-');
var month_index = Number(date_parts[1]) - 1;
var date_new = date_parts[0] + '-' + months[month_index] + '-' + date_parts[2];
$(this).val(date_new);
}); 

目前的日期格式为:31-12-2016

我需要采用以下格式:2016年12月31日

非常感谢提前!

0 个答案:

没有答案