【资料图】
varformatTime=function(time=newDate(),format){constTOTOW=e=>`0${e}`.substr(-2);//转成2位的格式1=>01constdate=newDate(time);constyyyy=date.getFullYear();constMM=TOTOW(date.getMonth()+1);constdd=TOTOW(date.getDate());consthh=TOTOW(date.getHours());constmm=TOTOW(date.getMinutes());constss=TOTOW(date.getSeconds());letresult;if(format){result=format.replace(/yyyy/i,yyyy).replace(/MM/,MM).replace(/dd/i,dd).replace(/hh/i,hh).replace(/mm/,mm).replace(/ss/i,ss);}else{result=`${yyyy}-${MM}-${dd}${hh}:${mm}:${ss}`;}returnresult;}setInterval(()=>{ letnow=formatTime(newDate(),"yyyy年MM月dd日hh时mm分ss秒");//月份必须是大写MM,分钟必须是小写mm,其他大小写都行 document.body.innerText=now;},1000)
// npm i momentmoment().startOf("day")// 当天零点moment().subtract(1,"days").startOf("day")// 昨天零点还有你这为啥过1秒才叫零点?
展开全部一、js自己使用使用new Date()类型变量的getTime获得同样的结果,但是是客户机的,而且是毫秒,需要除以1千二、可以这样写代码把time值传递给JS变量:var t=
你的意思是把时间戳转换成日期吗?如果是下面的方法就可以。vardate=newDate(1505014315514);Y=date.getFullYear()+"-";M=(date.getMonth()+1<10?"0"+(date.getMonth()+1):date.getMonth()+1)+"-";D=date.getDate()+"";h=date.getHours()+":";m=date.getMinutes()+":";s=date.getSeconds();console.log(Y+M+D+h+m+s);
下一篇:最后一页
Copyright@ 2015-2022 百科大全版权所有 备案号:豫ICP备2021032478号-16 联系邮箱:89 71 80 9@qq.com