当前位置: 移动技术网 > IT编程>开发语言>JavaScript > javascript日期转换 时间戳转日期格式

javascript日期转换 时间戳转日期格式

2019年07月19日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:

date.prototype.format = function(format)
{
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;
}
var testdate = new date( 1320336000000 );//这里必须是整数,毫秒
var teststr = testdate.format("yyyy年mm月dd日hh小时mm分ss秒");
var teststr2 = testdate.format("yyyymmdd hh:mm:ss");
alert(teststr + " " + teststr2);

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网