欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jQuery实现简单日期格式化功能示例

程序员文章站 2022-09-08 14:05:34
本文实例讲述了jquery实现简单日期格式化功能。分享给大家供大家参考,具体如下: 代码如下,引入jquery后直接后加入以下代码刷新可测试 date.prot...

本文实例讲述了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日期与时间操作技巧总结》、《jquery拖拽特效与技巧总结》、《jquery扩展技巧总结》、《jquery常见经典特效汇总》、《jquery选择器用法总结》及《jquery常用插件及用法总结

希望本文所述对大家jquery程序设计有所帮助。