微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript日期格式化方法小结

本文实例总结了javascript日期格式化方法分享给大家供大家参考,具体如下:

采用Prototype:

rush:js;"> 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; }

把这段代码放在里面。

然后调用时采用如下语句即可:
<div class="codetitle"><a style="CURSOR: pointer" data="59408" class="copybut" id="copybut59408" onclick="doCopy('code59408')"> 代码如下:

<div class="codebody" id="code59408">new Date().Format("yyyy-MM-dd hh:mm:ss")

具体可参考前面一篇《<a target="_blank" href="//www.jb51.cc/article/76548.htm">javascript中Date format(js日期格式化)方法小结》

另外获取当前日期的函数如下:


<div class="jb51code">
<pre class="brush:js;">
<SCRIPT LANGUAGE="JavaScript">

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐