获取现在时间 并转换格式
class Point{
nowTime(format){ //时间转换格式
let date = new Date(),times;
if(format=='yy-mm-dd hh:mm:ss'){//yy-mm-dd hh:mm:ss
times=date.getFullYear() +"-"+
((date.getMonth()+1)>=10?(date.getMonth()+1):'0'+
(date.getMonth()+1)) +"-"+ (date.getDate()>=10? date.getDate():'0'+ date.getDate())+" "+
(date.getHours()>=10? date.getHours():'0'+ date.getHours())+":"+
(date.getMinutes()>=10? date.getMinutes():'0'+ date.getMinutes())+":"+
(date.getSeconds()>=10? date.getSeconds():'0'+ date.getSeconds());
}else if(format=='yy-mm-dd'){//yy-mm-dd
times = date.toLocaleDateString().replace(///g,'-');
}else if(format=='hh:mm:ss'){
times =
(date.getHours()>=10? date.getHours():'0'+ date.getHours())+":"+
(date.getMinutes()>=10? date.getMinutes():'0'+ date.getMinutes())+":"+
(date.getSeconds()>=10? date.getSeconds():'0'+ date.getSeconds());
}else{
times = date.toLocaleString().replace(///g, "-");
}
return times;
}
};
let time = new Point();
console.log(time.nowTime('yy-mm-dd hh:mm:ss'))