求24小时时间JS代码
<scriptlanguage="javascript"><!--//以下是提示显示functionshowclock(){varoutStr="";vardate=ne...
<script language="javascript">
<!--
//以下是提示显示
function showclock()
{
var outStr="";
var date = new Date();
var hour = date.getHours();
var min_ = date.getMinutes();
var sec = date.getSeconds();
var col = ":";
var spc = " ";
outStr = hour+col+min_+col+sec+spc;
if(hour < 6){outStr=outStr+"明天不用上班了吗?"}
else if (hour < 8){outStr=outStr+"全新的一天!"}
else if (hour < 12){outStr=outStr+"上午好!"}
else if (hour < 14){outStr=outStr+"中午好"}
else if (hour < 18){outStr=outStr+"下午好!"}
else if (hour < 22){outStr=outStr+"晚上好!"}
else if (hour < 23){outStr=outStr+"夜深了!早点休息吧!"}
document.getElementById("clock").innerHTML=outStr;
}
setInterval("showclock()",1000);
document.write('<span id="clock"></span>');
// -->
</script>
去掉问候语!
要 时:分:秒 展开
<!--
//以下是提示显示
function showclock()
{
var outStr="";
var date = new Date();
var hour = date.getHours();
var min_ = date.getMinutes();
var sec = date.getSeconds();
var col = ":";
var spc = " ";
outStr = hour+col+min_+col+sec+spc;
if(hour < 6){outStr=outStr+"明天不用上班了吗?"}
else if (hour < 8){outStr=outStr+"全新的一天!"}
else if (hour < 12){outStr=outStr+"上午好!"}
else if (hour < 14){outStr=outStr+"中午好"}
else if (hour < 18){outStr=outStr+"下午好!"}
else if (hour < 22){outStr=outStr+"晚上好!"}
else if (hour < 23){outStr=outStr+"夜深了!早点休息吧!"}
document.getElementById("clock").innerHTML=outStr;
}
setInterval("showclock()",1000);
document.write('<span id="clock"></span>');
// -->
</script>
去掉问候语!
要 时:分:秒 展开
4个回答
展开全部
<script language="javascript">
<!--
//以下是提示显示
function showclock()
{
var outStr="";
var date = new Date();
var hour = date.getHours();
var min_ = date.getMinutes();
var sec = date.getSeconds();
var col = ":";
var spc = " ";
//时分秒小于10的时候在前面添加个0
if(hour<10)hour="0"+hour;
if(min_<10)min_="0"+min_;
if(sec<10)sec="0"+sec;
outStr = hour+col+min_+col+sec+spc;
document.getElementById("clock").innerHTML=outStr;
}
setInterval("showclock()",1000);
document.write('<span id="clock"></span>');
// -->
</script>
展开全部
要的是不是这个:
<script>
var myDate=new Date();
var date = myDate.getFullYear() + "-" + sup(myDate.getMonth()) + "-" + sup(myDate.getDate());
var time = sup(myDate.getHours()) + ":" + sup(myDate.getMinutes()) + ":" + sup(myDate.getSeconds());
alert(date + " " + time);
function sup ( n ) { return (n<10) ? '0'+n : n; }
</script>
输出:
2015-10-30 14:07:30
<script>
var myDate=new Date();
var date = myDate.getFullYear() + "-" + sup(myDate.getMonth()) + "-" + sup(myDate.getDate());
var time = sup(myDate.getHours()) + ":" + sup(myDate.getMinutes()) + ":" + sup(myDate.getSeconds());
alert(date + " " + time);
function sup ( n ) { return (n<10) ? '0'+n : n; }
</script>
输出:
2015-10-30 14:07:30
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<script language="javascript">
<!--
//以下是提示显示
function showclock()
{
var outStr="";
var date = new Date();
var hour = date.getHours();
var min_ = date.getMinutes();
var sec = date.getSeconds();
var col = ":";
var spc = " ";
outStr = hour+col+min_+col+sec+spc;
document.getElementById("clock").innerHTML=outStr;
}
setInterval("showclock()",1000);
document.write('<span id="clock"></span>');
// -->
</script>
<!--
//以下是提示显示
function showclock()
{
var outStr="";
var date = new Date();
var hour = date.getHours();
var min_ = date.getMinutes();
var sec = date.getSeconds();
var col = ":";
var spc = " ";
outStr = hour+col+min_+col+sec+spc;
document.getElementById("clock").innerHTML=outStr;
}
setInterval("showclock()",1000);
document.write('<span id="clock"></span>');
// -->
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把下面这段去掉就ok了
if(hour < 6){outStr=outStr+"明天不用上班了吗?"}
else if (hour < 8){outStr=outStr+"全新的一天!"}
else if (hour < 12){outStr=outStr+"上午好!"}
else if (hour < 14){outStr=outStr+"中午好"}
else if (hour < 18){outStr=outStr+"下午好!"}
else if (hour < 22){outStr=outStr+"晚上好!"}
else if (hour < 23){outStr=outStr+"夜深了!早点休息吧!"}
if(hour < 6){outStr=outStr+"明天不用上班了吗?"}
else if (hour < 8){outStr=outStr+"全新的一天!"}
else if (hour < 12){outStr=outStr+"上午好!"}
else if (hour < 14){outStr=outStr+"中午好"}
else if (hour < 18){outStr=outStr+"下午好!"}
else if (hour < 22){outStr=outStr+"晚上好!"}
else if (hour < 23){outStr=outStr+"夜深了!早点休息吧!"}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询