Android系统可以获取到page.data中的howDays更改后的数据,iOS系统显示是null,问题是new Date()方法在苹果ios端返回数据为空 new Date(12 + ‘-’ + 12 + ‘-’ + 2000);
部分源码如下:
data: {
dayAndMonth: {
howDays: ‘’,
},
}
btnCount_Click: function (s1, s2) { //s1=2018-08-21 s2=2018-08-23
var that = this;
var days = that.DateDiff(s1, s2);
that.setData({
dayAndMonth: {
howDays: days
}
});
},
DateDiff: function (sDate1, sDate2) { //sDate1和sDate2是2000-12-12格式
var aDate, oDate1, oDate2, iDays
aDate = sDate1.split("-")
oDate1 = new Date(aDate[1] + ‘-’ + aDate[2] + ‘-’ + aDate[0]) //转换为12-12-2000格式
aDate = sDate2.split("-")
oDate2 = new Date(aDate[1] + ‘-’ + aDate[2] + ‘-’ + aDate[0])
iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24) //把相差的毫秒数转换为天数
return iDays;
},