资讯详情

js时间戳转换年月日

直接上代码: 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;  
 }

标签: omon安全继电器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

 锐单商城 - 一站式电子元器件采购平台  

 深圳锐单电子有限公司