uniapp封裝函數(shù)的方法:1、獲取當(dāng)前時間,代碼為【hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours()】;2、格式化電話號碼。
本教程操作環(huán)境:windows7系統(tǒng)、uni-app2.5.1版本,該方法適用于所有品牌電腦。
推薦(免費):uni-app開發(fā)教程
uniapp封裝函數(shù)的方法:
獲取當(dāng)前時間,格式Y(jié)YYY-MM-DD HH:MM:SS
const GetNowTime = time => { var date = time, year = date.getFullYear(), month = date.getMonth() + 1, day = date.getDate(), hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(), minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(), second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds(); month >= 1 && month <= 9 ? (month = "0" + month) : ""; day >= 0 && day <= 9 ? (day = "0" + day) : ""; var timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second; return timer; }
格式化電話號碼
const GetPhone = phone => { let tel = phone.slice(0, 3) + '****' + phone.slice(7, 11); return tel; } module.exports = { GetNowTime, GetPhone }