js设置30分钟后展示

来源:互联网 发布:陈一发的淘宝店叫啥 编辑:程序博客网 时间:2024/06/05 09:23
<script>
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 x = "2010-09-28 14:50:26"; // 取得的TextBox中的时间

var replaceStr = "-";
var desStr=x.replace(new RegExp(replaceStr,'gm'),'/');
//alert(desStr);

 var time = new Date(desStr);
 var b = 30; //分钟数后
 time.setMinutes(time.getMinutes() + b, time.getSeconds(), 0);
 alert(time);
var time2 = time.format("yyyy-MM-dd hh:mm:ss");
alert(time2);

</script>