<SCRIPT language=javascript>
function String.prototype.ToStringByZero(count) //取自lostinet的函数库
{
   var str=this;
   while(str.length<count)str="0"+str;
      return str;
}
function DateDemo(){
   var d, s = "Today's date is: ";           // 声明变量。
   d = new Date();                           // 创建 Date 对象。
   s += d.getYear();                         // 获取年份。
   s += ((d.getMonth() + 1)+"").ToStringByZero(2);  // 获取月份。
   s += (d.getDate()+"").ToStringByZero(2);         // 获取日。
   s += (d.getHours()+"").ToStringByZero(2);        // 获取时。
   s += (d.getMinutes()+"").ToStringByZero(2);       // 获取分。
   s += (d.getSeconds()+"").ToStringByZero(2);       // 获取秒。   return(s);                                // 返回日期。
}
alert(DateDemo())
</script>

解决方案 »

  1.   

    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function Date.prototype.toString(){
    return this.getFullYear()+"年"+(this.getMonth()+1)+"月"+this.getDate()+"日"+" "+this.getHours()+"小时"+this.getMinutes()+"分"+this.getSeconds()+"秒";
    }
    var d = new Date();
    alert(d);
    //-->
    </SCRIPT>
      

  2.   

    (d.getMonth() + 1)
    这么写是什么意思?
    直接d.getMonth()不行吗?
      

  3.   

    getMonth返回的是0-11(12个月,不是1-12)之间,即一月是0,所以要+1就为1-12
      

  4.   

    function Date.prototype.toString
    这种写法,需要IE6.0以后吗?