javascript时间格式化函数
2010-01-07 18:22
1803人阅读
评论 (0)
Tags: javascript
写了半天,然后精简了一下,自己看了看还不错。呵呵
如果需要他其他格式的可以自己给Date添加其他的方法实现。
函数如下:
Date.prototype.toString = function() {
var y,m,d,h,i,s;
y = this.getYear()+1900;
m = this.getMonth()+1; m = (m<10) ? '0'+m : m;
d = this.getDate(); d = (d<10) ? '0'+d : d;
h = this.getHours(); h = (h<10) ? '0'+h : h;
i = this.getMinutes(); i = (i<10) ? '0'+i : i;
s = this.getSeconds(); s = (s<10) ? '0'+s : s;
return y+'-'+m+'-'+d+' '+h+':'+i+':'+s;
}