<script>
//
function getDays(t){
let date1 =new Date();
let date2 =new Date(t);
return Math.floor((date1.getTime()-date2.getTime())/1000/60/60/24);
}
// console.log(getDays("2010-10-5 14:12:34"));
// 年月日
function getYMD(sep="-"){
let date=new Date();
let y=date.getFullYear();
let m=date.getMonth()+1;
let d=date.getDate();
let ymd=[y,fullZero(m),fullZero(d)].join(sep);
// console.log(ymd)
return ymd;
}
// 时分秒
// 补零
function getHMS(sep=":"){
let date=new Date();
let h=date.getHours();
let m=date.getMinutes();
let s=date.getSeconds();
let hms=[fullZero(h),fullZero(m),fullZero(s)].join(sep);
return hms;
}
// 年月日 时分秒
function getYMDHMS(sep1,sep2){
return getYMD(sep1)+" "+getHMS(sep2);
}
function fullZero(n){
return n<10?"0"+n:n;
}
getYMD();
getHMS();
console.log( getYMDHMS("/","-"));
</script>
|