javascript---格式化日期

  1. <SCRIPT LANGUAGE="JavaScript">
  2. <!--
  3.      Date.prototype.format = function(format)  
  4. {  
  5.    var o = {  
  6.      "M+" : this.getMonth()+1, //month  
  7.      "d+" : this.getDate(),     //day  
  8.      "h+" : this.getHours(),   //hour  
  9.      "m+" : this.getMinutes(), //minute  
  10.      "s+" : this.getSeconds(), //second  
  11.      "q+" : Math.floor((this.getMonth()+3)/3), //quarter  
  12.      "S" : this.getMilliseconds() //millisecond  
  13.    }  
  14.    if(/(y+)/.test(format)) format=format.replace(RegExp.$1,  
  15.      (this.getFullYear()+"").substr(4 - RegExp.$1.length));  
  16.    for(var k in o)if(new RegExp("("+ k +")").test(format))  
  17.      format = format.replace(RegExp.$1,  
  18.        RegExp.$1.length==1 ? o[k] :    
  19.          ("00"+ o[k]).substr((""+ o[k]).length));  
  20.    return format;  
  21. }
  22. function rain()
  23. {
  24. obj1 = new Date().format("yyyy-MM-dd hh:mm:ss");
  25. obj2 = new Date().format("yyyy-MM-dd");
  26. obj3 = new Date().format("yyyy/MM/dd");
  27. obj4 = new Date().format("MM/dd/yyyy");
  28. alert("obj1="+obj1+ "/n   obj2="+obj2 +   "/n   obj3="   +obj3+   "/n   obj4="   +obj4);
  29. }
  30. //-->
  31. </SCRIPT>
  32. <input type="button" value="text"   οnclick="rain()">
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值