Home >Web Front-end >uni-app >How uniapp encapsulates functions
Uniapp encapsulation function method: 1. Get the current time, the code is [hour = date.getHours() < 10 ? "0" date.getHours() : date.getHours()]; 2. Format phone number.
The operating environment of this tutorial: windows7 system, uni-app2.5.1 version. This method is suitable for all brands of computers.
Recommended (free): uni-app development tutorial
Uniapp encapsulation function method:
Get the current time in the format YYYY-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; }
Format phone number
const GetPhone = phone => { let tel = phone.slice(0, 3) + '****' + phone.slice(7, 11); return tel; } module.exports = { GetNowTime, GetPhone }
The above is the detailed content of How uniapp encapsulates functions. For more information, please follow other related articles on the PHP Chinese website!