let date =newDate()
date.toLocaleString()// 2020/7/9 上午9:30:27//转化为dd-MM-yyyy HH:mm:sslet time = date.toLocaleString("en-US",{hour12:false}).replace(/\b\d\b/g,'0$&').replace(newRegExp('/','gm'),'-')//07-09-2020, 09:30:27//转化为yyyy-MM-dd HH:mm:sslet time = date.toLocaleString("zh-cn",{hour12:false}).replace(/\b\d\b/g,'0$&').replace(newRegExp('/','gm'),'-')// 2020-07-09 09:30:27let time = date.toLocaleString("zh-cn",{hour12:true}).replace(/\b\d\b/g,'0$&').replace(newRegExp('/','gm'),'-')// 2020-07-09 上午09:30:27
将yyyy-MM-dd转化为new Date()
newDate('2020-07-09 9:44:00');
获取当前的时间yyyy-MM-dd HH:mm:ss
let date =newDate();let year = date.getFullYear();let month = date.getMonth()+1;let day=date.getDate();let hours=date.getHours();let minu=date.getMinutes();let second=date.getSeconds();//判断是否满10let arr=[month,day,hours,minu,second];
arr.forEach(item=>{
item<10?"0"+item:item;})let dataFormat = year+'-'+arr[0]+'-'+arr[1]+' '+arr[2]+':'+arr[3]+':'+arr[4]
将时间戳转化为yyyy-MM-dd HH:mm:ss
let middleDate=newDate(1594352983166);let dateFormat = middleDate.toLocaleString('zh-CN',{hour12:false}).replace(/\b\d\b/g,'0$&').replace(newRegExp('/','gm'),'-')
文章目录获取指定日期范围new Date转化为yyyy-MM-dd HH:mm:ss将yyyy-MM-dd转化为new Date()获取当前的时间yyyy-MM-dd HH:mm:ss将时间戳转化为yyyy-MM-dd HH:mm:ss比较yyyy-MM-dd时间大小计算两个日期格式为(yyyy-MM-dd)相差几个月获取指定日期范围 function timeLimit(e) { let now = new Date(); //当前日期 let nowDayOfWeek = now.getDay(