// 时间格式转换 yyyy/mm/dd function formatTime(date) { var year = date.getFullYear() var month = date.getMonth() + 1 var day = date.getDate() var hour = date.getHours() var minute = date.getMinutes() var second = date.getSeconds() return [year, month, day].map(formatNumber).join('https://www.jb51.net/') + ' ' + [hour, minute, second].map(formatNumber).join(':') } // 时间格式转换 yyyy-mm-dd function formatTime2(date) { var year = date.getFullYear() var month = date.getMonth() + 1 var day = date.getDate() var hour = date.getHours() var minute = date.getMinutes() var second = date.getSeconds() return [year, month, day].map(formatNumber).join('-') } function formatDate(date, split) { var year = date.getFullYear() var month = date.getMonth() + 1 var day = date.getDate() return [year, month, day].map(formatNumber).join(split || '') } // 两位数自动补零 function formatNumber(n) { n = n.toString() return n[1] ? n : '0' + n } // 两位数以内的数字自动补零 function formatNumber(n) { n = n.toString() return n[1] ? n : '0' + n } // 计算变化多少天后的日期 function DateAddDay(d, days) { var d = new Date(d); return new Date(d.setDate(d.getDate() + days)); } // 获得本周周日的日期 function FirstDayInThisWeek(d) { var d = new Date(d); // console.log(formatTime(DateAddDay(d, 0 - d.getDay()))); return DateAddDay(d, 0 - d.getDay()); } // 判断类型 function Type(obj) { var typeStr = Object.prototype.toString.call(obj).split(" ")[1]; return typeStr.substr(0, typeStr.length - 1).toLowerCase(); } module.exports = { formatTime: formatTime, formatDate: formatDate, formatTime2, DateAddDay: DateAddDay, FirstDayInThisWeek: FirstDayInThisWeek, type: Type, addZero: formatNumber, }
调用组件
//json文件调用 "usingComponents": { "calendarMonth": "../../components/calendarWeek/index" }
页面调用组件
//mydata触发的点击日期时触发的事件 可获取当前点击的日期 <calendarMonth bindmydata="mydata"></calendarMonth>
当前页面js
//js里的事件 mydata(e){ //可获取日历点击事件 let data = e.detail.data console.log(data) }