//时间戳转换年月日方法
//format为“yyyy-mm-dd”、“yyyy/mm/dd”
//str传时间戳
//例: getUnixToDate('yyyy-mm-dd',"1618934400000")
//返回:"2021-04-21"
function getUnixToDate(format,str){
var oDate = new Date(parseInt(str)),
oYear = oDate.getFullYear(),
oMonth = oDate.getMonth()+1,
oDay = oDate.getDate(),
oHour = oDate.getHours(),
oMin = oDate.getMinutes(),
oSec = oDate.getSeconds();
if(format == 'yyyy-mm-dd'){
oTime = oYear +'-'+ getzf(oMonth) +'-'+ getzf(oDay) +' '+ getzf(oHour) +':'+ getzf(oMin) +':'+getzf(oSec);//最后拼接时间
}else if(format == 'yyyy/mm/dd'){
oTime = oYear +'/'+ getzf(oMonth) +'/'+ getzf(oDay) +' '+ getzf(oHour) +':'+ getzf(oMin) +':'+getzf(oSec);//最后拼接时间
}
return oTime.substring(0, 10);
}
//补0操作
function getzf(num){
if(parseInt(num) < 10){
num = '0'+num;
}
return num;
}
使用:
var employTime = getUnixToDate('yyyy-mm-dd',v.employTime)//employTime :"2021-04-21"