javascript实现时间格式输出FormatDate函数
2015-01-13 00:00
585 查看
本文实例讲述了javascript实现时间格式输出FormatDate函数。分享给大家供大家参考。具体如下:
javascript没有提供像fmt标签一样对日期时间型内容格式输入的函数:
下面是我下的时间输出函数,使用时直接放到标签内,调用。代码如下
使用时直接用
希望本文所述对大家的javascript程序设计有所帮助。
javascript没有提供像fmt标签一样对日期时间型内容格式输入的函数:
下面是我下的时间输出函数,使用时直接放到标签内,调用。代码如下
Date.prototype.Format = function(fmt) { //author: meizz if (this == "Invalid Date") { return ""; } 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; }
使用时直接用
new Date( 时间变量 ).Format("yyyy-MM-dd HH:mm:ss")
希望本文所述对大家的javascript程序设计有所帮助。
相关文章推荐
- javascript实现时间格式输出FormatDate函数
- javascript 时间格式输出FormatDate函数
- javascript两行代码按指定格式输出日期时间
- javaScript输出指定的时间格式
- JavaScript下的时间格式处理函数Date.prototype.format
- javascript按指定格式输出文件最后更新时间
- javascript按指定格式输出文件最后更新时间
- javascript两行代码按指定格式输出日期时间
- javascript实现时间格式的控制以及容错处理
- JavaScript下的时间格式处理函数Date.prototype.format
- javascript实现实时输出当前的时间
- 使用DateFormat类输出各种格式的时间(上)
- javascript两行代码按指定格式输出日期时间
- 在自己写的formatName基础上,写个,将时间转化为自定义的输出字符串格式信息
- JSTL fmt:formatDate 的输出时间日期格式
- javascript输出时间格式:2009年7月7日
- 秒转 时间格式 JavaScript seconds to time with format hh:mm:ss
- Android 开发之 SimpleDateFormat 类解析&输出指定格式的日期时间字符串
- Javascript扩展String.prototype实现格式金额、格式时间、字符串连接、计算长度、是否包含、日期计算等功能
- javascript两行代码按指定格式输出日期时间