Countdown, calculate how long X days X hours X minutes X seconds before the Mid-Autumn Festival

Countdown, calculate how long X days X hours X minutes X seconds before the Mid-Autumn Festival

insert image description here

div{
    
    
				width: 500px;
				height: 50px;
				background-color: lightcyan;
				text-align: center;
				margin: 0 auto;
				color: olive;
				border-radius: 300px;
				padding-top: 18px;
				font-size: 20px;
				
			}
var time=new Date('2022,9,10')
		//对象时间戳时间减去当前的时间
	    var time1=time.getTime()-Date.now()
		//化为秒
		 time1=time1/1000
		 var seconds=parseInt(time1%60)
		 var minutes=parseInt((time1%3600)/60)
		 var houres=parseInt((time1%(24*3600))/3600)
		 var date=parseInt(time1/(24*3600))
		 var str=`距离中秋还有:${
      
      date}${
      
      houres}小时:${
      
      minutes}分钟:${
      
      seconds}`
		 //渲染到页面
		cont.innerHTML=str

Guess you like

Origin blog.csdn.net/m0_65792710/article/details/126822099