<script>
function a(s){return s.replace(/-(\d)(?=\D|$)/g,"-0$1");}
alert(a("2003-1-6"));
alert(a("2003-10-6"));
alert(a("2003-1-16"));
</script>
function a(s){return s.replace(/-(\d)(?=\D|$)/g,"-0$1");}
alert(a("2003-1-6"));
alert(a("2003-10-6"));
alert(a("2003-1-16"));
</script>
function MakeArray(n) {
this.length = n
return this
}
function customDateString(oneDate) { var theMonth = oneDate.getMonth() + 1;
var theYear = oneDate.getYear();
if (theMonth<10){theMonth="0"+theMonth}
var theDay = oneDate.getDate()
if (theDay<10){theDay="0"+theDay}
if (theYear < 1900) { theYear = theYear + 1900}; var today = theYear + "-" + theMonth + "-" + theDay; return today;
}document.write(customDateString(new Date()))</script>
谢谢你,但是
oneDate.getMonth() 会出错。因为
输入oneDate是2003-7-7系统不认为是日期fason(阿信):您的方法对了。谢谢
function a(s){return s.replace(/([-: ])(\d)(?=\D|$)/g,"$10$2");}
alert(a("2003-1-6 12:1:1"));
alert(a("2003-10-6 2:1:5"));
alert(a("2003-1-16 22:7:5"));
function a(v) {
v += "."
re = /-(\d[^\d])/g;
while(re.test(v))
v = v.replace(re,"-0$1");
return v.substr(0,v.length-1);
}
alert(a("2003-1-1"));
alert(a("2003-11-1"));
alert(a("2003-1-11"));
</script>
function a(v) {
return v.replace(/\b(\d)\b/g,'0$1')
}
alert(a("2003-1-1"));
alert(a("2003-11-1 12:1:1"));
alert(a("2003年1月11日"));
</script>
这句话我看不太懂,什么意思,请指教~~~