目录
一、数据库字段
二、 后端JavaBean字段
三、前端表格年龄展示
一、数据库字段
`depart_birthday` datetime NULL DEFAULT NULL COMMENT '员工出生日期',
二、 后端JavaBean字段
@JsonFormat 设置格式化
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date departBirthday;
三、前端表格年龄展示
表格代码:
<el-table-columnprop="departBirthday"label="年龄"width="80px"><template slot-scope="scope"><span>{{scope.row.departBirthday | changeAge}}</span></template>
</el-table-column>
日期转年龄,过滤代码:
//过滤
filters:{//日期改为年龄changeAge(birthStr){let birthdays = new Date(birthStr.replace(/-/g, "/"));let d = new Date();let age = d.getFullYear() - birthdays.getFullYear() - (d.getMonth() < birthdays.getMonth() || (d.getMonth() == birthdays.getMonth() && d.getDate() < birthdays.getDate()) ? 1 : 0);return age ;},