项目用到了求时间差,发现安卓没问题,但是ios会在计算部分报错NAN
function DateDiff(sDate1, sDate2) {
var aDate, oDate1, oDate2, iDays
aDate = sDate1.split("-")
oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
aDate = sDate2.split("-")
oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24)
return iDays
}
将时间里的‘-’全部替换为‘/’即可
function DateDiff(sDate1, sDate2) {
var aDate, oDate1, oDate2, iDays
aDate = sDate1.split("-")
oDate1 = new Date(aDate[1] + '/' + aDate[2] + '/' + aDate[0])
aDate = sDate2.split("-")
oDate2 = new Date(aDate[1] + '/' + aDate[2] + '/' + aDate[0])
iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24)
return iDays
}