JS日期格式化
2015-10-10 14:50
393 查看
// 日期格式化 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; };
相关文章推荐
- JS自定义MAP对象
- jsp实现Servlet文件下载的方法
- JSP分页c:foreach分页代码以及效果新闻发布系统
- js中 parseFloat() 函数
- js权威指南——函数摘要
- 基于Raphael.js的实现
- js工具收集汇总
- js中获得项目名称
- JS正则表达式验证账号、手机号、电话和邮箱
- javascript 返回上一页面:onclick="javascript:history.back(-1);"
- 如何处理js的跨域问题
- jstl核心标签库使用
- 各大互联网公司2014前端笔试面试题–JavaScript篇
- js验证集合
- jsp获取一个对象和list对象
- soanrqube 扫描javascript代码
- JavaScript获取当前根目录
- js 设置cookie 读取cookie
- 10月17日 黑客马拉松 — 用MeteorJS开发全栈应用
- FlexPaper 里的pdf2json.exe 下载地址