最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
vue中对时间戳代码处理方式
时间:2022-06-29 01:45:28 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下vue中对时间戳代码处理方式,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
vue对时间戳的处理
1、自建js文件
文件位置根据自己的项目位置自定义
export function formatDate(date, fmt) {
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
}
let o = {
'M+': date.getMonth() + 1,
'd+': date.getDate(),
'h+': date.getHours(),
'm+': date.getMinutes(),
's+': date.getSeconds()
};
for (let k in o) {
if (new RegExp(`(${k})`).test(fmt)) {
let str = o[k] + '';
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
}
}
return fmt;
};
function padLeftZero(str) {
return ('00' + str).substr(str.length);
};
2、在组件模板中引用定义好的时间戳函数
{{time | formatDate}}
3、设置好在script中的引用和定义
vue时间戳转换
后台拿时间数据,一般不是时间格式,而是一串数组,这个时候就需要转换,然后才可以使用了
add_time(row, column, cellValue, index) {
if (cellValue == null || cellValue == "") return "";
let date = new Date(parseInt(cellValue) * 1000);
let Y = date.getFullYear() + '-';
let M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) + '-' : date.getMonth() + 1 + '-';
let D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' ';
let h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
let m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
return Y + M + D;
},
相关文章
- 知乎网页版快速入口-知乎网页版一键登录平台 03-15
- 163邮箱登录入口-官网网页版163邮箱登录 03-15
- 羞羞漫画最新版下载安装-羞羞漫画官方正版免费下载v1.0.6 03-15
- 智学网成绩查询入口-学生端成绩查询入口 03-15
- cet4成绩查询入口-cet4官网成绩查询入口 03-15
- QQ经典版下载安装最新版本-QQ经典版app官方正版安全下载入口 03-15