当前位置:网站首页>全局过滤器(处理时间格式)
全局过滤器(处理时间格式)
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} `;
});
边栏推荐
- 【MPC】②quadprog求解正定、半正定、负定二次规划
- Oracle和JSON的結合
- 使用强大的DBPack处理分布式事务(PHP使用教程)
- How to solve the problem of SQL?
- [encounter Django] - (II) database configuration
- Is it safe to buy funds on the access letter?
- Error: missing revert data in call exception
- Personal mall two open Xiaoyao B2C mall system source code - Commercial Version / group shopping discount seckill source code
- 北汽蓝谷:业绩承压,极狐难期
- What a high commission! The new programmer's partner plan is coming. Everyone can participate!
猜你喜欢
LeetCode. 515. Find the maximum value in each tree row___ BFS + DFS + BFS by layer
[.net6] use ml.net+onnx pre training model to liven the classic "Huaqiang buys melons" in station B
【论文阅读】Trajectory-guided Control Prediction for End-to-end Autonomous Driving: A Simple yet Strong Ba
CRC 校验
Submission lottery - light application server essay solicitation activity (may) award announcement
Personal mall two open Xiaoyao B2C mall system source code - Commercial Version / group shopping discount seckill source code
使用强大的DBPack处理分布式事务(PHP使用教程)
个人商城二开逍遥B2C商城系统源码-可商用版/拼团拼购优惠折扣秒杀源码
The exclusive collection of China lunar exploration project is limited to sale!
数据库实验报告(一)
随机推荐
《数据安全法》出台一周年,看哪四大变化来袭?
推荐一款 JSON 可视化工具神器!
A new round of popularity of digital collections opens
flutter path_ Provider: ^2.0.10 can get temporary directory
Zero foundation software testing must see, 10 years of testing old bird's conscience suggestions (a total of 15)
How does MySQL copy table data from one database to another (two databases are not linked to the same database)
华为HMS Core携手超图为三维GIS注入新动能
Mutual conversion of pictures in fluent uint8list format and pictures in file format
About database: how to avoid deadlock in gbase 8s
Can I choose to open an account on CICC securities? Is it safe?
数字藏品市场新局面
问下群里的各位,有使用flink oracle cdc的logminer方案,在生产上稳定运行的实际
IDEA运行报错Command line is too long. Shorten command line for...
LeetCode.515. 在每个树行中找最大值___逐一BFS+DFS+按层BFS
北汽蓝谷:业绩承压,极狐难期
[matytype] insert MathType inter line and intra line formulas in CSDN blog
[.NET6]使用ML.NET+ONNX预训练模型整活B站经典《华强买瓜》
Detailed explanation of linear regression in machine learning
选择在中金证券上炒股开户可以吗?安全吗?
机器学习之线性回归详解