1.獲取今天0點時間戳:/*1、日期格式轉換
*用法說明:
* 直接呼叫:輸入時間(毫秒數)和 格式
* formatdate(new date().gettime());
* formatdate(new date().gettime(),'yy年mm月dd日');
* formatdate(new date().gettime(),'今天是yy/mm/dd hh:mm:ss');
*/function formatdate(time,format='yy-mm-dd hh:mm:ss'));
// replace(regexp/substr,replacement) 方法用於在字串中用一些字元替換另一些字元,或替換乙個與正規表示式匹配的子串。
var newtime = format.replace(/yy/g,year)
.replace(/mm/g,prearr[month]||month)
.replace(/dd/g,prearr[day]||day)
.replace(/hh/g,prearr[hour]||hour)
.replace(/mm/g,prearr[min]||min)
.replace(/ss/g,prearr[sec]||sec);
return newtime;
} /* 2、獲取當前時間八點到第二天八點 時間
*用法說明:
* console.log(calculationtime(new date().gettime(),new date().gettime()+86400000,'yy-mm-dd hh:mm:ss')[0]);
* console.log(calculationtime(new date().gettime(),new date().gettime()+86400000,'yy-mm-dd hh:mm:ss')[1]);
* 分割---獲取前面:split("/")[0]; 後面:split("/")[1];--------隨手寫的,怕忘了
*/function calculationtime(time,tomorrowtime,format='yy-mm-dd hh:mm:ss'));
var newtime = format.replace(/yy/g,year)
.replace(/mm/g,prearr[month]||month)
.replace(/dd/g,prearr[day]||day)
.replace(/hh/g,prearr[hour]||hour)
.replace(/mm/g,prearr[min]||min)
.replace(/ss/g,prearr[sec]||sec);
var tomorrow = format.replace(/yy/g,tomorrowyear)
.replace(/mm/g,prearr[tomorrowmonth]||tomorrowmonth)
.replace(/dd/g,prearr[tomorrowday]||tomorrowday)
.replace(/hh/g,prearr[tomorrowhour]||tomorrowhour)
.replace(/mm/g,prearr[tomorrowmin]||tomorrowmin)
.replace(/ss/g,prearr[tomorrowsec]||tomorrowsec);
startstop.push(newtime);
startstop.push(tomorrow);
return startstop;
}
const start = new date(new date(new date().tolocaledatestring()).gettime());
2.獲取今天23:59:59點時間戳:
const start = new date(new date(new date().tolocaledatestring()).gettime()+246060*1000-1);
js時間戳轉換日期格式和日期計算
1 function formatdate datetime 14 15 var date new date 16 console.log formatdate date 2018 05 26 23 09 26根據開始日期和期限,計算結束日期 1 date 日期字串yyyy mm dd,如 2016...
js時間戳轉換日期格式和日期計算
1 function formatdate datetime 1415 var date new date 16 console.log formatdate date 2018 05 26 23 09 26 根據開始日期和期限,計算結束日期 1 date 日期字串yyyy mm dd,如 2016...
js日期格式轉換
var d new date var str d.getfullyear d.getmonth 1 d.getdate alert str var mydate new date mydate.getyear 獲取當前年份 2位 mydate.getfullyear 獲取完整的年份 4位,1970 ...