[JavaScript] 日期格式化函数+调用方法 →→→→→进入此内容的聊天室

来自 , 2020-11-22, 写在 JavaScript, 查看 107 次.
URL http://www.code666.cn/view/63923f49
  1. Date.prototype.format = function(format){
  2.     var o = {
  3.         "M+" : this.getMonth()+1, //month
  4.         "d+" : this.getDate(),    //day
  5.         "h+" : this.getHours(),   //hour
  6.         "m+" : this.getMinutes(), //minute
  7.         "s+" : this.getSeconds(), //second
  8.         "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
  9.         "S" : this.getMilliseconds() //millisecond
  10.     };
  11.     if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
  12. (this.getFullYear()+"").substr(4 - RegExp.$1.length));
  13.     for(var k in o){
  14.         if(new RegExp("("+ k +")").test(format))
  15.             format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] :("00"+ o[k]).substr((""+ o[k]).length));
  16.     }
  17.     return format;
  18. }
  19. alert(new Date().format("yyyy-MM-dd hh:mm:ss"));
  20.  

回复 "日期格式化函数+调用方法"

这儿你可以回复上面这条便签

captcha