function dateFormat(dtStr){
const dt = new Date(dtStr)
const y =dt.getFullYear()
const m =dt.getMonth() +1
const d =dt.getDate()
const hh =dt.getHours()
const mm =dt.getMinutes()
const ss =dt.getSeconds()
return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
}
module.exports={
dateFormat
}
4.转化html特殊字符
function zhuanHtml(html){
return html.replace(/<|>|"|&/g,(i)=>{
switch(i){
case "<":
return <
case ">":
return >
case '"':
return "
case '&':
return &
}
})
}
function huanHtml(html){
return str.replace(<|>|"|&/g,(i)=>{
switch(i){
case "<":
return '<';
case ">":
return '>';
case '"':
return '"';
case '&':
return '&';
}
})
}