js實例教程-js格式化獲取到的系統時間的代碼教程

发布时间:2018-11-23 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了js實例教程-js格式化獲取到的系統時間的代碼教程脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
小寶典致力於為廣大程序猿(媛)提供高品質的代碼服務,請大家多多光顧小站,小寶典在此謝過。

1.js方法

 //時間轉換格式     Date.PRototyPE.format = function(fmt) {        VAR o = {           ";m+" : this.getMonth()+1,                 //月份           "d+" : this.getDate(),                    //日           "h+" : this.getHours(),                   //小時           "m+" : this.getMinutes(),                 //分           "s+" : this.getSeconds(),                 //秒           "q+" : Math.floor((this.getMonth()+3)/3), //季度           "S"  : this.getMilliseconds()             //毫秒       };       if(/(y+)/.test(fmt)) {              fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));       }       for(var k in o) {          if(new RegExp("("+ k +")").test(fmt)){               fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));           }       }      return fmt;      } 

2.使用案例

 var da=new Date().format("yyyy/MM/dd");

1.js方法

 //時間轉換格式     Date.prototype.format = function(fmt) {        var o = {           "M+" : this.getMonth()+1,                 //月份           "d+" : this.getDate(),                    //日           "h+" : this.getHours(),                   //小時           "m+" : this.getMinutes(),                 //分           "s+" : this.getSeconds(),                 //秒           "q+" : Math.floor((this.getMonth()+3)/3), //季度           "S"  : this.getMilliseconds()             //毫秒       };       if(/(y+)/.test(fmt)) {              fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));       }       for(var k in o) {          if(new RegExp("("+ k +")").test(fmt)){               fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));           }       }      return fmt;      } 

2.使用案例

 var da=new Date().format("yyyy/MM/dd");

覺得可用,就經常來吧!Javascript技巧 腳本寶典 歡迎評論哦! js技巧,巧奪天工,精雕玉琢。小寶典獻醜了!

脚本宝典总结

以上是脚本宝典为你收集整理的js實例教程-js格式化獲取到的系統時間的代碼教程全部内容,希望文章能够帮你解决js實例教程-js格式化獲取到的系統時間的代碼教程所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。