js 显示时间

本文介绍了一段使用JavaScript实现的时间日期显示及个性化问候语的代码。该代码能够根据当前时间显示具体的日期信息,并根据不同时间段输出相应的问候语。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<script language="JavaScript" >
<!---
today=new Date();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
var timeValue = "<FONT COLOR=red>" + ((hours >12) ? hours -12 :hours); timeValue += ((minutes < 10) ? "<BLINK><FONT COLOR=red>:</FONT></BLINK>0" : "<BLINK><FONT COLOR=red>:</FONT></BLINK>") + minutes+"</FONT></FONT>";
timeValue += (hours >= 12) ? "<FONT COLOR=blue><I><B>pm</B></I></FONT>" : "<FONT COLOR=blue><B><I>am</I></B></FONT>";
function initArray(){
this.length=initArray.arguments.length
for(var i=0;i<this.length;i++)
this[i+1]=initArray.arguments[i] }
var d=new initArray("<font color=RED>星期日","<font color=red>星期一","<font color=red>星期二","<font color=red>星期三","<font color=red>星期四","<font color=red>星期五","<font color=GREEN>星期六"); document.write("<font color=red>",today.getYear(),"<font color=red>年","<font color=red>",today.getMonth()+1,"<font color=red>月","<font color=red>",today.getDate(),"<font color=red>日 </FONT>",d[today.getDay()+1]);
//-->
</script>


<script>
now = new Date();
var hour2 = now.getHours()
var tmp="";
var sstr = "";
if(hour2 < 6){sstr=("凌晨好!")}
else if (hour2 < 9){sstr=("早上好!")}
else if (hour2 < 12){sstr=("上午好!")}
else if (hour2 < 14){sstr=("中午好!")}
else if (hour2 < 17){sstr=("下午好!")}
else if (hour2 < 19){sstr=("傍晚好!")}
else if (hour2 < 22){sstr=("晚上好!")}
else {sstr=("夜里好!")}
document.write(sstr);
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值