//取得当前时间
window.onload = function getNowTime(){ //取得当前时间 var now= new Date(); var year=now.getYear(); var month=now.getMonth()+1; var day=now.getDate(); var hour=now.getHours(); var minute=now.getMinutes(); var second=now.getSeconds(); var nowdate=year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second; document.getElementById("break_date").value = nowdate; }
------解决方案-------------------- var d = new Date();
var str = d.getFullYear()+"-0"+(d.getMonth()+1)+"-0"+d.getDate();
alert(str) ------解决方案-------------------- 封装下呗。
<script type="text/javascript">
Date.prototype.format = function(partten)
{
if(partten ==null ------解决方案-------------------- partten=='')
{
partten = 'y-m-d' ;
}
var y = this.getYear();
var m = this.getMonth()+1;
var d = this.getDate();
var r = partten.replace(/y+/gi,y);
r = r.replace(/m+/gi,(m<10?"0":"")+m);
r = r.replace(/d+/gi,(d<10?"0":"")+d);
return r;
}
//调用方式
alert((new Date()).format());
alert((new Date()).format("y-m-d"));
alert((new Date()).format("y/m/d"));
alert((new Date()).format("m/d/y"));