求帮忙修改时间格式。感谢
javascript吧
全部回复
仅看楼主
level 1
例如6小时48分2秒,求帮忙修改为06小时48分02秒 也就是双位数
代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>倒计时,每天00:00分重新倒计时。每天重复</title>
<style type="text/css">
#time {
font-size: 24px;
}
</style>
</head>
<body>
<script language=JavaScript>
var now = new Date();//当前时间
var isjx=0;
function GetServerTime(){
var d= now.getYear()+"/"+now.getMonth()+"/"+now.getDate()+" 00:00:00";//设置每天的16:30 为节点
var urodz = new Date(d);
now.setTime(now.getTime()+250);
days = (urodz - now) / 1000 / 60 / 60 / 24;
daysRound = Math.floor(days);
hours = (urodz - now) / 1000 / 60 / 60 - (24 * daysRound);
hoursRound = Math.floor(hours);
minutes = (urodz - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
minutesRound = Math.floor(minutes);
seconds = (urodz - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
secondsRound = Math.round(seconds);
if((hoursRound==0 && minutesRound==0 && secondsRound==0)){//都等于0 说明过了16:30
isjx=1;
}
//判断
if(isjx==0 && (parseFloat(now.toTimeString().substr(0,2)+ now.toTimeString().substr(3,3).substr(0,2)+now.toTimeString().substr(6,7) )<=162959)){
document.getElementById("time").innerHTML = "距离开始 还有"+hoursRound + "小时" + minutesRound + "分钟" + secondsRound +"秒" ;
}else {
document.getElementById("time").innerHTML = "距离结束 还有 "+hoursRound + "小时" + minutesRound + "分钟" + secondsRound +"秒";
}
}
setInterval("GetServerTime()",250);
</script>
<span id="time"></span>
</body>
</html>
2013年06月24日 09点06分 1
level 13
//格式化日期显示 "yyyy-MM-dd hh:mm:ss";Date.prototype.format = function (format) {if(!format) return this.toString();var weeksCN = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"), weeksEN = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");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"W": weeksCN[this.getDay()], "w":weeksEN[this.getDay()]}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] : ("0" + o[k]).match(/\d{2}$/)[0]);}}return format;};
2013年06月25日 00点06分 3
1