首先下载第三方模块
//下载命令
npm install dateformat
导入第三方模块提供的方法
const template =require('art-template');
const path = require('path');
//引入第三方模块
const dateFormat = require('dateformat');
const rotue = path.join(__dirname,'06.art');
//导入模板变量 固定写法 可以在art文件中调用dateFormat方法
template.defaults.imports.dateFormat = dateFormat;
let html = template(rotue,{
time:new Date()
})
console.log(html);
使用这个方法
//第一个参数是要格式化的时间
// yyyy代表年份 后面的-是代表用什么来分割 mm是月份 dd是日
{{dateFormat(time,'yyyy-mm-dd')}}
运行结果