2008-07-14
javascript 对时间对象的格式化
关键字: 时间对象的格式化
<script language="JavaScript">
Date.prototype.format = function(format) //author: meizz
{
var o = {
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}
if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
(this.getFullYear()+"").substr(4 - RegExp.$1.length));
for(var k in o)if(new RegExp("("+ k +")").test(format))
format = format.replace(RegExp.$1,
RegExp.$1.length==1 ? o[k] :
("00"+ o[k]).substr((""+ o[k]).length));
return format;
}
alert(new Date().format("yyyy-MM-dd hh:mm:ss"));
</script>
- 18:00
- 浏览 (50)
- 评论 (0)
- 分类: javascript 点滴
- 相关推荐
发表评论
- 浏览: 22918 次
- 性别:

- 来自: 青岛

- 详细资料
搜索本博客
我的相册
111 046
共 4 张
共 4 张
最新评论
-
JAVA数据类型转换
谢谢楼主,说的很详细,好好学习下!
-- by sky21 -
JAVA数据类型转换
虽然是基础的东西, 但能总结出来还不错, 虽然有某些欠缺
-- by zhanjia -
15位和18位身份证的正则表 ...
不错,我收藏了
-- by jasongreen -
15位和18位身份证的正则表 ...
不错,我收藏了
-- by jasongreen -
DOS中 Orcle9i服务的启动 ...
呵呵
-- by jiake0504






评论排行榜