转自:http://blog.csdn.net/xiaojian0819/article/details/5688996

Date.prototype.format = function(format)
{
 var o = {
 "M+" : this.getMonth()+1, //month
 "d+" : this.getDate(),    //day
 "h+" : this.getHours(),   //hour
 "m+" : this.getMinutes(), //minute
 "s+" : this.getSeconds(), //second
 "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
 "S" : this.getMilliseconds() //millisecond
 }
 if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
 (this.getFullYear()+"").substr(4 - RegExp.$1.length));
 for(var k in o)if(new RegExp("("+ k +")").test(format))
 format = format.replace(RegExp.$1,
 RegExp.$1.length==1 ? o[k] :
 ("00"+ o[k]).substr((""+ o[k]).length));
 return format;
}

 

对Date的原型进行了改造,用起来比较方便

var d1 = new Date();
d1.format('yyyy-MM-dd');

var d2 = new Date();
d2.format('yyyy-MM-dd');

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-03-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
猜你喜欢
  • 2022-12-23
  • 2021-08-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
相关资源
相似解决方案