当前位置:网站首页>全局过滤器(处理时间格式)
全局过滤器(处理时间格式)
2022-07-01 10:53:00 【宇智波-林中路】
padStart()用于头部补全
padStart(2,'0') 将转换成字符串的'3',不够两位时,前面加个0,输出就是03,彻底解决日期如:2020-07-06这类问题
//padStart(2,'0') 将转换成字符串的'6',不够两位时,前面加个0,输出就是06,彻底解决日期如:2020-07-06这类问题
var month = 6;
var newMonth = (month + "").padStart(2, "0");
console.log(newMonth); //06
//padStart(3,'0') 将转换成字符串的'7',不够三位时,前面加个00,输出就是007
var day = 7;
var newDay = day.toString().padStart(3, "0");
console.log(newDay); //007
padEnd()用于尾部补全
//padEnd(2,'0') 将转换成字符串的'6',不够两位时,后面加个0,输出就是60,用处不多
var month = 6;
var newMonth = (month + "").padEnd(2, "0");
console.log(newMonth); //60
//padEnd(3,'0') 将转换成字符串的'7',不够三位时,后面加个00,输出就是700,用处不多
var day = 7;
var newDay = day.toString().padEnd(3, "0");
console.log(newDay); //700
全局过滤器方法1:
// main.js文件中
// 全局过滤器('过滤器的名字',处理的时间数据)
Vue.filter("dataFormat", (data) => {
const dt = new Date(data);
// 月份+1 转成字符串处理数据
const y = dt.getFullYear();
const m = (dt.getMonth() + 1).toString().padStart(2, "0");
const d = dt.getDate().toString().padStart(2, "0");
const hh = dt.getHours().toString().padStart(2, "0");
const mm = dt.getMinutes.toString().padStart(2, "0");
const ss = dt.getSeconds.toString().padStart(2, "0");
return `${y}-${m}-${d} ${hh}:${mm}:${ss} `;
});
边栏推荐
- 内存泄漏定位工具之 valgrind 使用
- Half of 2022 has passed, isn't it sudden?
- CRC verification
- [.NET6]使用ML.NET+ONNX预训练模型整活B站经典《华强买瓜》
- Can I choose to open an account on CICC securities? Is it safe?
- 我国蜂窝物联网用户已达 15.9 亿,年内有望超越移动电话用户
- 爬虫(2) - Requests(1) | Requests模块的深度解析
- 华为HMS Core携手超图为三维GIS注入新动能
- 基于Matlab的开环Buck降压斩波电路Simulink仿真电路模型搭建
- 数据库实验报告(二)
猜你喜欢
【邂逅Django】——(二)数据库配置
bash: ln: command not found
Half of 2022 has passed, isn't it sudden?
Detailed explanation of linear regression in machine learning
Infinite innovation in cloud "vision" | the 2022 Alibaba cloud live summit was officially launched
《百年巨匠》数字藏品中奖名单公布
JS基础--数据类型
十年磨一剑:蚂蚁集团可观测性平台 AntMonitor 揭秘
12 product management platforms that everyone is using
[paper reading] trajectory guided control prediction for end to end autonomous driving: a simple yet strong Ba
随机推荐
[.net6] use ml.net+onnx pre training model to liven the classic "Huaqiang buys melons" in station B
Is it safe to buy funds on the access letter?
LeetCode. 515. Find the maximum value in each tree row___ BFS + DFS + BFS by layer
爬虫(2) - Requests(1) | Requests模块的深度解析
678. 有效的括号字符串
[matytype] insert MathType inter line and intra line formulas in CSDN blog
中国探月工程独家藏品限量发售!
12 product management platforms that everyone is using
106. 从中序与后序遍历序列构造二叉树
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
Simulink simulation circuit model of open loop buck buck buck chopper circuit based on MATLAB
Want to open an account, is it safe to open an account of Huatai Securities online?
[.NET6]使用ML.NET+ONNX预训练模型整活B站经典《华强买瓜》
SQL server2014 failed to delete the database, with an error offset of 0x0000
CRC 校验
How do clients request databases?
CodeBlocks 左侧项目栏消失,workspace 自动保存项目,Default workspace,打开上次的workspace,工作区(图文教程,已解决)
prism journal导航按钮的可用性探索记录
数据库实验报告(一)
Oracle和JSON的結合