dateInit: function (setYear, setMonth) {
let dateArr = [];
let arrLen = 0;
let now = setYear ? new Date(setYear, setMonth) : new Date();
let year = setYear || now.getFullYear();
let nextYear = 0;
let month = setMonth || now.getMonth();
let nextMonth = (month + 1) > 11 ? 1 : (month + 1);
let startWeek = new Date(year + ',' + (month + 1) + ',' + 1).getDay();
let dayNums = new Date(year, nextMonth, 0).getDate();
let obj = {};
let num = 0;
if (month + 1 > 11) {
nextYear = year + 1;
dayNums = new Date(nextYear, nextMonth, 0).getDate();
}
arrLen = startWeek + dayNums;
for (let i = 0; i < arrLen; i++) {
if (i >= startWeek) {
num = i - startWeek + 1;
obj = {
isToday: parseInt(year * 10000 + (month + 1) * 100 + num),
dateNum: num,
weight: 5
}
} else {
obj = {};
}
dateArr[i] = obj;
}
this.setData({
dateArr: dateArr
})
let nowDate = new Date();
let nowYear = nowDate.getFullYear();
let nowMonth = nowDate.getMonth() + 1;
let nowWeek = nowDate.getDay();
let getYear = setYear || nowYear;
let getMonth = setMonth >= 0 ? (setMonth + 1) : nowMonth;
if (nowYear == getYear && nowMonth == getMonth) {
this.setData({
isTodayWeek: true,
todayIndex: nowWeek
})
} else {
this.setData({
isTodayWeek: false,
todayIndex: -1
})
}
},
报错了吧,安卓跟IOS获取时间的格式不一样
你可以检查一下,你页面渲染的时候这个参数前后面有没有带空格,<view>{{time}}<view>中间不能有空格,ios真机显示有可能会有问题。
第二种,我碰到过字段名如果是time的话,ios真机显示有问题,改成别的名字就好了!~
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date
当向new Date()或者Date.parse()传递字符串的时候,你是无法预知解析结果正确性的,因为字符串的解析完全取决于不同浏览器的实现;
你可以尝试new Date(year, month, day, ...)这种方式创建日期对象,以保证万无一失;
const newDate = (year, monthIndex = 0, day = 1, hour = 0, min = 0, sec = 0, ms = 0) => new Date(year, monthIndex, day, hour, min, sec, ms);
如果你遇到了在 iOS 上无法渲染组件的问题,请确认在创建 Date 对象时没有使用
new Date('2020-01-01')
这样的写法,iOS 不支持以中划线分隔的日期格式,正确写法是new Date('2020/01/01')
yy-mm-dd hh:mm:ss 有用这种格式吧?将它改为yy/mm/dd h-mm-ss
onLoad: function (options) { let zz = JSON.parse(options.jsonStr) this.setData({ title: zz.title, note: zz.note }) let now = new Date(); let year = now.getFullYear(); let month = now.getMonth() + 1; this.dateInit(); this.setData({ nowYear: year, nowMonth: month, year: year, month: month, isToday: year * 10000 + month * 100 + now.getDate() })