复制代码代码如下所示:
date.prototype.format =
函数(格式){
var { { { {
M +:this.getmonth()+ 1, / /月
D:this.getdate(), / /天
H:this.gethours(), / /小时
M +:this.getminutes(), / /分钟
+:this.getseconds(), / /二
Q+:Math.floor(((this.getmonth()+ 3)/ 3), / /季度
S: this.getMilliseconds () //millisecond
}
如果( / /(Y +)。试验(格式))格式(1美元= format.replace正则表达式,
(this.getfullyear()+)。Substr(4—9。1美元。长度));
为(O变量K)如果(new RegExp((钾))。试验(格式))
格式(1美元= format.replace正则表达式,
正则表达式。1.length = 1美元} { k:
(00+ O { k })。Substr((+ O { k })。长度));
返回格式;
}
无功tempdate =新的
日期();
TempDate.toLocaleDateString()9月4日 / / 2013
TempDate.format(yyyy-mm-dd) / / 2013-09-04