uniapp 时间戳 获取问题

最近uniapp 试水 差点溺水 简单粗暴分享给大家 :

一、获取时间戳

正常浏览器new Date()

uniapp 中

	let time=new Date()
	console.log(time,"time")  // {} time
	let time1=new Date().getTime()
	console.log(time1,"time1") // 1.6512e+12 time1 

1.6512e+12 是科学计数法 new Date().getTime().toFixed() 转成13位的时间戳

二、时间戳转年月日

正常浏览器

uniapp 中

let t=new Date().getTime().toFixed()
console.log(t,"t")  // 1651199198673 t
console.log( typeof t)  // string
let time=new Date(Number(t))  
console.log(time)   // {}

三、最后的方案

请大神  moment.js

附链接:Moment.js 中文网

uni-app中使用moment_一个菜鸡,的博客-CSDN博客_uniapp使用moment

终于上岸了 ^0^

 


版权声明:本文为yuanmengdage原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。