您好,欢迎访问一九零五行业门户网

jQuery如何实现简单日期格式化功能

本文主要和大家介绍jquery实现简单日期格式化功能,涉及jquery调用javascript针对日期格式转换扩展实现日期格式化功能相关操作技巧,需要的朋友可以参考下,希望能帮助到大家。
代码如下,引入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"))); })
运行结果如下:
相关推荐:
javascript创建日期对象和日期格式化方法介绍
js的日期格式化功能
angularjs 日期格式化详解
以上就是jquery如何实现简单日期格式化功能的详细内容。
其它类似信息

推荐信息