javascript初始化时间

来源:互联网 发布:淘宝怎样卖电子书 编辑:程序博客网 时间:2024/05/04 23:05
<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>

 

0 0
原创粉丝点击