js获取当前时间和前30天时间

	//获取当前时间
	let myDate = new Date();
    let arr = myDate.toLocaleDateString();
    console.log(arr,'rediddatarediddatarediddatarediddata');
    //获取三十天前日期
    let lw = new Date(myDate - 1000 * 60 * 60 * 24 * 30);//最后一个数字30可改,30天的意思
    let lastY = lw.getFullYear();
    let lastM = lw.getMonth()+1;
    let lastD = lw.getDate();
    let startdate=lastY+"-"+(lastM<10 ? "0" + lastM : lastM)+"-"+(lastD<10 ? "0"+ lastD : lastD);//三十天之前日期
    console.log(startdate,'startdatestartdatestartdatestartdate')
    原文作者:管家金闪闪
    原文地址: https://blog.csdn.net/Litao131319/article/details/109818696
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞