uniapp算两个时间年月日之间相差多少天,以及获取当前年月日,获取当前时间的时间戳
·
一、计算两个时间之间相差多少天
aDate = sDate1.split("-");
var f = sDate1.split(' ', 2);
var d = (f[0] ? f[0] : '').split('-', 3);
var t = (f[1] ? f[1] : '').split(':', 3);
oDate1= (new Date(
parseInt(d[0], 10) || null,
(parseInt(d[1], 10) || 1) - 1,
parseInt(d[2], 10) || null,
parseInt(t[0], 10) || null,
parseInt(t[1], 10) || null,
parseInt(t[2], 10) || null
)).getTime() ;
//oDate1我用的系统时间,改为你自己的时间即可
oDate1=Math.round(oDate1)
oDate2=Math.round(Date.parse(new Date()))
iDays = parseInt(Math.abs(oDate1 - oDate2) /1000 / 60 / 60 / 24); //把相差的毫秒数转换为天数
return iDays +1; //返回相差天数
sDate1的值是2023-6-6
二、获取当前年月日
const d = new Date()
const year = d.getFullYear()
let month = d.getMonth() + 1
month = month < 10 ? `0${month}` : month
const date = d.getDate()
this.maxDate = `${year}-${month}-${date}`
三、获取当前时间的时间戳
Number(new Date())
更多推荐



所有评论(0)