当前位置:网站首页>时间戳转换为日期格式、获取当前时间戳
时间戳转换为日期格式、获取当前时间戳
2022-08-11 00:10:00 【小任睡不醒`】
将时间戳转换成日期格式
//定义一个方法
filterTime(time) {
let times=time.toString();
if(times.length==10){//如果时间戳为10位给转13位
time=(time*1000)
}
const dateTime = new Date(time)//获取一个时间对象
const Y = dateTime.getFullYear()
const M = dateTime.getMonth() + 1 < 10 ? '0'+(dateTime.getMonth()+1) : dateTime.getMonth()+1
const D = dateTime.getDate()< 10 ? '0'+(dateTime.getDate()) : dateTime.getDate()
const h = (dateTime.getHours() < 10 ? '0' + dateTime.getHours() : dateTime.getHours())
const m = (dateTime.getMinutes() < 10 ? '0' + dateTime.getMinutes() : dateTime.getMinutes())
const s=(dateTime.getSeconds() < 10 ? '0' + dateTime.getSeconds() : dateTime.getSeconds())
//组装一下
return `${Y}-${M}-${D} ${h}:${m}:${s}`
},
调用方法
let newTime= Date.parse(new Date());//获取当前时间
newTime=this.filterTime(newTime)
打印出来当前时间
边栏推荐
- 【mysql】mysql分别按年/月/日/周分组统计数据
- Where can I download IEEE papers?
- Software Testing Certificate (1) - Software Evaluator
- Call activity of Activiti7 sub-process
- 线上突然查询变慢怎么核查
- YOLOv5的Tricks | 【Trick11】在线模型训练可视化工具wandb(Weights & Biases)
- Web-based meal ordering system in epidemic quarantine area
- 5. Lombok
- [C language] binary search (half search)
- 软件测试证书(1)—— 软件评测师
猜你喜欢
11. 自定义转换器
sqlmap combined with dnslog fast injection
软件测试证书(1)—— 软件评测师
[C language] First understanding of pointers
“蔚来杯“2022牛客暑期多校训练营2 DGHJKL题解
[C Language Chapter] Detailed explanation of bitwise operators (“<<”, “>>”, “&”, “|”, “^”, “~”)
YOLOv5的Tricks | 【Trick13】YOLOv5的detect.py脚本的解析与简化
Where can I download IEEE papers?
百战RHCE(第四十八战:运维工程师必会技-Ansible学习3-构建Ansible清单)
李彦宏拆墙交朋友,大厂“塑料友情”能否帮百度啃下硬骨头?
随机推荐
[Excel知识技能] 将数值格式数字转换为文本格式
How to do patent mining, the key is to find patent points, in fact, it is not too difficult
② 关系数据库标准语言SQL 数据定义(创建、修改基本表)、数据更新(增删改)
[C language] binary search (half search)
关于科研学习中的几个问题:如何看论文?如何评价工作?如何找idea?
学习Apache ShardingSphere解析器源码(一)
[Excel knowledge and skills] Convert "false" date to "true" date format
UOJ#749-[UNR #6]稳健型选手【贪心,分治,主席树】
【经典排序】快速排序
Dump文件生成,内容,以及分析
【mysql】mysql分别按年/月/日/周分组统计数据
[C language] Implementation of guessing number game
C language, operators of shift operators (> >, < <) explanation
Call activity of Activiti7 sub-process
云原生-VMware虚拟机安装Kubesphere实战(一)
“蔚来杯“2022牛客暑期多校训练营2 DGHJKL题解
12. 处理 JSON
2022.8.10-----leetcode.640
英文文献阅读时,如何做笔记?
编程语言为什么有变量类型这个概念?