my-tools-hulisheng-123
v1.0.0
Published
npm i my-tools ## 2.导入方式 const my = require("my-tools") ## 3.格式化时间 ``` 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 =
Downloads
1
Readme
1.安装方式
1.1使用npm安装
npm i my-tools
2.导入方式
const my = require("my-tools")
3.格式化时间
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 '&';
}
})
}