成长带走的不只是时光,还带走了那些不害怕失去的勇气。谢谢那些怀疑我的人,给我成长的洗礼,让我更加孤独。
本文实例讲述了jQuery实现简单日期格式化功能。分享给大家供大家参考,具体如下:
代码如下,引入jquery后直接后加入以下代码刷新可测试
Date.prototype.Format = function (fmt) { //author: meizz 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; } $(function(){ var date=new Date(); alert(JSON.stringify(date.Format("yyyy年MM月dd hh:mm:ss"))); })
运行结果如下:
希望本文所述对大家jQuery程序设计有所帮助。
以上就是jQuery实现简单日期格式化功能示例。幸福不是在于我们多么努力的去争取是在于我们多么努力的去珍惜!更多关于jQuery实现简单日期格式化功能示例请关注haodaima.com其它相关文章!