微信小程序苹果手机页面上显示时间异常,安卓机正常问题
错误代码
1var date = '2021-03-06 17:00:00' 2var dateTime = new Date(date)
正确代码
1var date = '2021-03-06 17:00:00' 2var dateTime = new Date(date.replace(/-/g,'/'))
时间戳转换字符串方法
1const formatTime = date => { 2 const year = date.getFullYear() 3 const month = date.getMonth() + 1 4 const day = date.getDate() 5 const hour = date.getHours() 6 const minute = date.getMinutes() 7 const second = date.getSeconds() 8 9 return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':') 10} 11 12const formatNumber = n => { 13 n = n.toString() 14 return n[1] ? n : '0' + n 15} 16 17function isBlank(str){ 18 if (Object.prototype.toString.call(str) ==='[object Undefined]'){//空 19 return true 20 } else if ( 21 Object.prototype.toString.call(str) === '[object String]' || 22 Object.prototype.toString.call(str) === '[object Array]') { //字条串或数组 23 return str.length==0?true:false 24 } else if (Object.prototype.toString.call(str) === '[object Object]') { 25 return JSON.stringify(str)=='{}'?true:false 26 }else{ 27 return true 28 } 29} 30 31module.exports = { 32 formatTime: formatTime, 33 isBlank: isBlank 34}
