安装
、、、 npm install hzh-time 、、、
导入
、、、js const itheima = require("hzh-time"); 、、、
格式化时间
、、、js // 调用 dateFormat 对时间进行格式化 const date = new Date(); const formatDate = itheima.formatTime(date, "yyyy-MM-dd hh:mm:ss"); console.log(formatDate); // 2020-06-21 16:00:00 、、、
转义HTML中的特殊字符
、、、js // 带转换的HTML字符串 const htmlStr = '
123
' // 调用 htmlEscape 对字符串进行转义 const str = time.htmlEscape(htmlStr); console.log(str); // 结果 <h1 title="abc">标签为h1<span>123& 、、、 标签为h1还原HTML中的特殊字符
、、、js // 带转义后的HTML字符串 const str = '<h1 title="abc">标签为h1<span>123 </span></h1>' // 调用 htmlUnescape 对字符串进行还原 const htmlStr = time.htmlUnescape(str); console.log(htmlStr); // 结果
123
、、、 标签为h1开源协议
ISC