js時間轉換,能夠把時間轉換成yyyymmdd格式或yyyymm格式




//type為1則轉換成yyyymmdd格式,type為2則轉換成yyyymm格式

function formatTime(time,type){
var temp_time=new Number(time);
var temp_date=new Date(temp_time);
var temp_year1="";
var temp_month1="";
var temp_day1="";
if(type==1){
temp_year1=temp_date.getFullYear();
temp_month1=(temp_date.getMonth()+1)>9?(temp_date.getMonth()+1):"0"+(temp_date.getMonth()+1);
temp_day1=(temp_date.getDate())>9?(temp_date.getDate()):"0"+(temp_date.getDate());
return temp_year1.toString()+temp_month1.toString()+temp_day1.toString();
}else if(type==2){
temp_year1=temp_date.getFullYear();
temp_month1=(temp_date.getMonth()+1)>9?(temp_date.getMonth()+1):"0"+(temp_date.getMonth()+1);
return temp_year1.toString()+temp_month1.toString();
}
}

該代碼來自百度知道:842366175 |四級采納率52%

請測試后使用。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM