<script> 
function Date.prototype.toString(){
var tempMonth=this.getMonth()+1;
tempMonth=(tempMonth.toString().length==1)?("0"+tempMonth):tempMonth;
var tempDate=this.getDate();
tempDate=(tempDate.toString().length==1)?("0"+tempDate):tempDate;
return this.getFullYear()+"年"+tempMonth+"月"+tempDate+"日";
}
alert(new Date())
</script> 

解决方案 »

  1.   

    我感觉这样是自己找麻烦,如果要形成hhmmss格式的6位时间字符串,还不要定义一个120位的字符串?
    所以在此求教一个更简单的方法,但不喜欢用if。
      

  2.   

    <script language="javascript"> 
    //补0函数  
    function appendZero(s){
    return   ("00"+   s).substr((s+"").length);
    }     
      var   d   =   new   Date();   
      alert(d.getFullYear() +"-" +appendZero(d.getMonth() +1) + "-" + appendZero(d.getDate()));
    </script>
      

  3.   


    <script language="javascript" type="text/javascript">
    var date = new Date();
    alert(date.toLocaleDateString());
    </script>
      

  4.   

    谢谢各位帮忙,代码都不错!其中lqscoke提供的函数最好用!