微信开发者工具创建的默认工具脚本.md
这是微信开发者工具基础模板默认的工具脚本内容,自己觉得他写的非常优雅,忍不住的拉出来,闲暇时,多看两眼。
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}`
}
module.exports = {
formatTime
}