标签:mon date() int fun string datetime return UNC [1]
monthDateFun(startDate, endDate) {
function formatDatetime(datetimeString) {//日期格式化 兼容移动端IOS跟安卓日期出现的NAN
var datetime;
if (isNaN(Date.parse(datetimeString))) {
datetime = datetimeString && new Date(Date.parse(datetimeString.replace(/-/g, ‘/‘).replace(/T/g, ‘ ‘)));
} else {
datetime = datetimeString && new Date(Date.parse(datetimeString));
}
return datetime;
}
var sdate = formatDatetime(startDate);//格式化日期
var starDateText = formatDatetime(endDate);//格式化日期
var totalMonth;
var starTime = (sdate && (sdate.getFullYear() + "-" + (sdate.getMonth() + 1) + "-" + sdate.getDate())) || ‘‘;
var endTime = (starDateText && (starDateText.getFullYear() + "-" + (starDateText.getMonth() + 1) + "-" + starDateText.getDate())) || ‘‘;
// 拆分年月日
starTime = starTime.split(‘-‘);
// 得到月数
starTime = parseInt(starTime[0]) * 12 + parseInt(starTime[1]);
// 拆分年月日
endTime = endTime.split(‘-‘);
// 得到月数
endTime = parseInt(endTime[0]) * 12 + parseInt(endTime[1]);
totalMonth = Math.abs(starTime - endTime);
return totalMonth || 0;
},
标签:mon date() int fun string datetime return UNC [1]
原文地址:https://www.cnblogs.com/fancyLee/p/9960048.html