当前位置:网站首页>时间戳转换为日期格式、获取当前时间戳
时间戳转换为日期格式、获取当前时间戳
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)打印出来当前时间

边栏推荐
猜你喜欢

鲲鹏编译调试及原生开发工具基础知识

YOLOv5的Tricks | 【Trick12】YOLOv5使用的数据增强方法汇总

Dump file generation, content, and analysis

Design and Realization of Employment Management System in Colleges and Universities

SAS data processing technology (1)

SQL注入基础---order by \ limit \ 宽字节注入
![[Excel knowledge and skills] Convert numeric format numbers to text format](/img/fb/79d6928456f090d47f0fe7a5074979.png)
[Excel knowledge and skills] Convert numeric format numbers to text format

How engineers treat open source

【考虫 六级英语】语法课笔记

详谈二叉搜索树
随机推荐
16. File upload
Which translation software is more accurate [Free]
"NIO Cup" 2022 Nioke Summer Multi-School Training Camp 2 DGHJKL Problem Solution
Special class and type conversion
[C Language Chapter] Detailed explanation of bitwise operators (“<<”, “>>”, “&”, “|”, “^”, “~”)
地下管廊可视化管理系统搭建
YOLOv5的Tricks | 【Trick10】从PyTorch Hub加载YOLOv5
Dump文件生成,内容,以及分析
Cache knowledge summary
Mysql. Slow Sql
深度解析volatile关键字(保证够全面)
SQL injection base
Mysql.慢Sql
How engineers treat open source
How to quickly grasp industry opportunities and introduce new ones more efficiently is an important proposition
leetcode 前K个高频单词
如何便捷获取参考文献的引用格式?
Promote the high-quality development of denim clothing
2022.8.10-----leetcode.640
【.NET Core】使用 NPOI 读写Excel 文件