vue filter方法-时间格式化
2024-10-15 17:38:03
plugins/filter.js
import Vue from 'vue'
// 时间格式化
// 用法:<div>{{data | dataFormat('yyyy-MM-dd hh:mm:ss')}}</div>
Vue.filter('formatDate', function (value, fmt) {
let getDate = new Date(value);
let o = {
'M+': getDate.getMonth() + 1,
'd+': getDate.getDate(),
'h+': getDate.getHours(),
'm+': getDate.getMinutes(),
's+': getDate.getSeconds(),
'q+': Math.floor((getDate.getMonth() + 3) / 3),
'S': getDate.getMilliseconds()
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (getDate.getFullYear() + '').substr(4 - RegExp.$1.length))
}
for (let k in o) {
if (new RegExp('(' + k + ')').test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
}
}
return fmt;
})
nuxt.config.js
plugins: ['@/plugins/element-ui', '@/plugins/filters.js'],
最新文章
- UI: 多窗口
- Wix 安装部署教程(九) --用WPF做安装界面
- Android获取焦点所在控件
- POJ3613 Cow Relays [矩阵乘法 floyd类似]
- svn删除目录后提交显示Item &#39;XXXX&#39; is out of date解决方法
- 解决UITabeleViewCell的分割线不能铺满问题
- Red and Black(简单dfs)
- linux路由表配置
- Spark SQL 源代码分析之 In-Memory Columnar Storage 之 in-memory query
- NPOI 2.0 教程(二):编辑既存的EXCEL文件
- word2-寻找社交新浪微博中的目标用户
- Pandas系列之入门篇
- 公众号用户发送消息后台PHP回复没有反应的解决办法
- cf1144E 假高精度平均数
- SpringBoot(十):读取application.yml下配置参数信息,java -jar启动时项目修改参数
- [转]SOA架构设计经验分享&mdash;架构、职责、数据一致性
- jenkins和svn搭建自动代码构建发布
- 第二篇:服务消费者(rest + ribbon)
- STM32.定时器
- SQL Server 2012 表分区
热门文章
- mysql:Cannot proceed because system tables used by Event Scheduler were found damaged at server start
- sench touch 自定义小图标(转)
- .Net Core中的通用主机(二)——托管服务
- 更改WebBrowser控件的用户代理
- 9款国内外垂直领域的在线作图工具:那些可以替代Visio的应用!【转】
- 命令 上传项目到git中
- Win10系统的SurfacePro4如何重装系统-2 重装WIN10系统
- asp.net mvc 实战化项目之三板斧
- cmd命令行的ping用法
- Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -