Vue3后台管理系统框架之时间格式化封装

编程入门 行业动态 更新时间:2024-10-17 21:19:05

Vue3后台<a href=https://www.elefans.com/category/jswz/34/1769858.html style=管理系统框架之时间格式化封装"/>

Vue3后台管理系统框架之时间格式化封装

一般每条数据都会有创建时间或者更新时间

由于我们在数据库设置时间类型为datatime

如何把element plus 表格中的创建时间格式进行格式化?

如:2023-11-03T13:59:05.000Z修改为2023-11-03 21:59

修改为 YYYY-MM-DD HH:mm格式

export const formatDate = (dateTimeString: any) => {const date = new Date(dateTimeString)const year = date.getFullYear()const month = String(date.getMonth() + 1).padStart(2, '0')const day = String(date.getDate()).padStart(2, '0')const hours = String(date.getHours()).padStart(2, '0')const minutes = String(date.getMinutes()).padStart(2, '0')return `${year}-${month}-${day} ${hours}:${minutes}`
}

 年月日这种形式formatDate 方法来将日期时间字符串转换为 YYYY-MM-DD 的格式

 formatDate(dateTimeString) {const date = new Date(dateTimeString);const year = date.getFullYear();const month = String(date.getMonth() + 1).padStart(2, '0');const day = String(date.getDate()).padStart(2, '0');return `${year}-${month}-${day}`;}
<el-table-column prop="created_time" label="创建时间" width="180"><template #default="scope">{{ formatDate(scope.row.created_time) }}</template></el-table-column><el-table-column prop="update_time" label="更新时间" width="180"><template #default="scope">{{ formatDate(scope.row.update_time) }}</template></el-table-column>

更多推荐

Vue3后台管理系统框架之时间格式化封装

本文发布于:2023-11-16 15:07:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627197.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:管理系统   后台   框架   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!