UNPKG

wx-mini-weview

Version:

weixin UI

40 lines (31 loc) 882 B
const formatTime = date => { const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() const hour = date.getHours() const minute = date.getMinutes() const second = date.getSeconds() return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}` } const formatNumber = n => { n = n.toString() return n[1] ? n : `0${n}` } const toPx = function (value) { const systemInfo = wx.getWindowInfo(); const screenWidth = systemInfo.windowWidth; if(typeof(value) == 'number'){ return value } if (value.includes('rpx')) { const rpxValue = parseFloat(value.replace('rpx', '')); return rpxValue * screenWidth / 750; } if (value.includes('px')) { return parseFloat(value.replace('px', '')); } return value } module.exports = { formatTime, toPx }