直接上代码: getDate该方法接受两个参数,参数为需要转换的格式,如yyyy-mm-dd,或yyyy/mm/dd,可根据需要独立添加其他格式;参数2为时间戳
///转换年月日方法 function getDate(format,str){
var oDate = new Date(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;
};
//补0操作
function getzf(num){
if(parseInt(num) < 10){
num = '0'+num;
}
return num;
}