uniapp算两个时间年月日之间相差多少天

aDate = sDate1.split("-");
var f = sDate1.split(' ', 2);
var d = (f[0] ? f[0] : '').split('-', 3);
var t = (f[1] ? f[1] : '').split(':', 3);
oDate1= (new Date(
    parseInt(d[0], 10) || null,
    (parseInt(d[1], 10) || 1) - 1,
    parseInt(d[2], 10) || null,
    parseInt(t[0], 10) || null,
    parseInt(t[1], 10) || null,
    parseInt(t[2], 10) || null
)).getTime() ;
//oDate1我用的系统时间,改为你自己的时间即可
oDate1=Math.round(oDate1)
oDate2=Math.round(Date.parse(new Date()))
iDays = parseInt(Math.abs(oDate1 - oDate2) /1000 / 60 / 60 / 24); //把相差的毫秒数转换为天数
return iDays +1;  //返回相差天数

sDate1的值是2023-6-6

猜你喜欢

转载自blog.csdn.net/stars______/article/details/130752343