<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>
所以在此求教一个更简单的方法,但不喜欢用if。
//补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>
<script language="javascript" type="text/javascript">
var date = new Date();
alert(date.toLocaleDateString());
</script>