//比较两个时间大小 var myDate = new Date(); var date = myDate.getFullYear() + ‘-‘ + (myDate.getMonth() + 1) + ‘-‘ + myDate.getDate(); //选择的时间 var OneMonth = birth.substring(5, birth.lastIndexOf(‘-‘)); var OneDay = birth.substring(birth.length, birth.lastIndexOf(‘-‘) + 1); var OneYear = birth.substring(0, birth.indexOf(‘-‘)); //当前的时间 var TwoMonth = date.substring(5, date.lastIndexOf(‘-‘)); var TwoDay = date.substring(date.length, date.lastIndexOf(‘-‘) + 1); var TwoYear = date.substring(0, date.indexOf(‘-‘)); var cha = ((Date.parse(OneMonth + ‘/‘ + OneDay + ‘/‘ + OneYear) - Date.parse(TwoMonth + ‘/‘ + TwoDay + ‘/‘ + TwoYear)) / 86400000); if (cha >= 1) { //说明选择的时间比当前时间大;return; } 当然了,这种方法有局限性,若时间类型为yyyy/MM/dd则先需要将转换年月日分割的标识变更即可;写这些,不为别的,只想在我的代码之路上留下印记,日后方便自已,方便他人;
时间: 2024-10-01 02:46:49