利用moment时间插件,在sequlize 的model 定义里面加上时间转换函数。
首先引入moment插件:
const moment = require('moment');
<li style="box-sizing:border-box;outline:0px;margin:0px;padding:0px 8px;list-style:none;font-size:inherit;overflow-wrap:break-word;border-right:1px solid #C5C5C5;color:#999999;">
</li>
然后 给字段 createTime 增加 get 方法:
createTime: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: sequelize.literal('CURRENT_TIMESTAMP'),
get(){
return moment(this.getDataValue('createTime')).format('YYYY-MM-DD HH:mm:ss');
}
}