您的位置:首页 > Web前端 > JavaScript

javascript初始化时间

2015-07-30 10:11 597 查看
<script type="text/javascript">
 function init(){
    var tempDate = new Date();
var currDate = ChangeDateToString(tempDate);
    var startDate = document.getElementById("queryStartDate");
var endDate =document.getElementById("queryEndDate");
startDate.value = currDate;
endDate.value = currDate;
 }
 function ChangeDateToString(DateIn){  
    var Year = 0;  
    var Month = 0;  
    var Day = 0;       
    var CurrentDate = "";  
              
    //初始化时间  
     Year  = DateIn.getYear();  
     Month  = DateIn.getMonth()+1;  
     Day  = DateIn.getDate();       
     CurrentDate = Year + "-";  
     if (Month >= 10 ){  
         CurrentDate = CurrentDate + Month + "-";  
     } else{  
         CurrentDate = CurrentDate + "0" + Month + "-";  
     }  
     if (Day >= 10 ){  
         CurrentDate = CurrentDate + Day ;  
     } else{  
         CurrentDate = CurrentDate + "0" + Day ;  
     }  
  
     return CurrentDate;  
 } 
 </script>

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: