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

边栏推荐
- ArcGIS Pro 创建tpk
- 如何做专利挖掘,关键是寻找专利点,其实并不太难
- How to recover data from accidentally deleted U disk, how to recover deleted data from U disk
- 2022.8.10-----leetcode.640
- 如何利用原生JS实现回到顶部以及吸顶效果
- CF1427F-Boring Card Game【贪心】
- sqlmap combined with dnslog fast injection
- [Excel knowledge and skills] Convert numeric format numbers to text format
- NOR FLASH闪存芯片ID应用之软件保护场景
- App regression testing, what are the efficient testing methods?
猜你喜欢

12. Handling JSON

分布式.性能优化
![[C Language Chapter] Detailed explanation of bitwise operators (“<<”, “>>”, “&”, “|”, “^”, “~”)](/img/7a/4c4e74a294074e1f5fc573d21adb20.png)
[C Language Chapter] Detailed explanation of bitwise operators (“<<”, “>>”, “&”, “|”, “^”, “~”)

有哪些可以投稿软件工程/系统软件/程序设计语言类外文期刊、会议?

91.(cesium之家)cesium火箭发射模拟

如何做专利挖掘,关键是寻找专利点,其实并不太难

8. WEB 开发-静态资源访问

YOLOv5的Tricks | 【Trick10】从PyTorch Hub加载YOLOv5

YOLOv5的Tricks | 【Trick11】在线模型训练可视化工具wandb(Weights & Biases)

Is there a way out in the testing industry if it is purely business testing?
随机推荐
Ali P7 bask in January payroll: hard to fill the, really sweet...
sqlmap combined with dnslog fast injection
“蔚来杯“2022牛客暑期多校训练营3 DF题解
[数据可视化] 图表设计原则
盘点美军的无人机家底
[Excel knowledge and skills] Convert "false" date to "true" date format
[C] the C language program design, dynamic address book (order)
In 22 years, the salary of programmers nationwide in January was released, only to know that there are so many with annual salary of more than 400,000?
[C language] First understanding of pointers
从0开始设计JVM ,忘记名词跟上思路一次搞懂
Mysql.慢Sql
② 关系数据库标准语言SQL 数据定义(创建、修改基本表)、数据更新(增删改)
5. Lombok
全排列思路详解
详谈二叉搜索树
There is no recycle bin for deleted files on the computer desktop, what should I do if the deleted files on the desktop cannot be found in the recycle bin?
学习Apache ShardingSphere解析器源码(一)
Where can I download IEEE papers?
【考虫 六级英语】语法课笔记
Promote the high-quality development of denim clothing