且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将2位数日期转换(格式化)为4位数日期

更新时间:2023-02-10 15:30:27

你可以先试着分开输入部分

you can try,first, to seperate the parts of the input

...
var input=$(this).val();
var month=input.substr(0,2)-1;
var day=input.substr(3,2);
var year=parseInt("20"+ input.substr(6,2));

然后启动一个新的Date对象:

and then initate a new Date object:

var date= new Date(year,month,day);

或将其写回现场,如下所示:

or write it back to the field, as you did:

$(this).val((date.getMonth()+1)+'/'+date.getDate()+'/'+date.getFullYear());