js 获取当前时间并格式化

function getNowDateFormate(now){
 strTime = now.toLocaleString();
 strYear = now.getYear();
 strMonth = now.getMonth();
 strDay = now.getDay();
   
 displayTime = strYear +"/"+strMonth+"/"+strDay;  
 if(strTime.substring(5,6)<10){
   var displayTime = strTime.substring(0,4)+"-0"+strTime.substring(5,6)+"-"+strTime.substring(7,9);
     }else{
   
   var displayTime = strTime.substring(0,4)+"-"+strTime.substring(5,7)+"-"+strTime.substring(8,10)
 };
 return displayTime;
}

你可能感兴趣的:(js)