今天分享⼀个javaScript制作12进制时钟特效的⼩题。
代码如下
> <!DOCTYPE html> <html> <head lang="en">
> <meta charset="UTF-8">
> <title>制作12进制的时钟特效</title> </head> <body> <div id="myclock"></div> <script type="text/javascript">
>
> function clock_12h()
> {
> var today = new Date(); //获得当前时间
> //获得年、⽉、⽇,Date()函数中的⽉份是从0-11计算
关于白露节气的诗> var year = FullYear();
> var month = Month()+1;
> var date = Date();
> var hour = Hours(); //获得⼩时、分钟、秒
麻花的家常做法> var minute = Minutes();
> var second = Seconds();
>
> var apm="AM"; //默认显⽰上午: AM发蜡
> if (hour>12) //按12⼩时制显⽰
> {
> hour=hour-12;
> apm="PM" ;
> }
> var weekday = 0;
> Day()){
> case 0:
> weekday = "星期⽇";
> break;
> case 1:
> weekday = "星期⼀";
> break;
> case 2:
> weekday = "星期⼆";
> break;
中秋祝福短信 领导> case 3:
> weekday = "星期三";
粟裕简历> break;
> case 4:
> weekday = "星期四";
> break;
> case 5:
> weekday = "星期五";
> break;
> case 6:
> weekday = "星期六";
潘粤明车祸> break;
> }
>
> /*设置div的内容为当前时间*/
> ElementById("myclock").innerHTML="<h2>你好,欢迎访问!</h2><h2>"+year+"年"+month+"⽉"+date+"⽇ "+hour+":"+minute+":" +second+" "+apm+" "+weekday+"</h2>";
>
> }
> /*使⽤setInterval()每间隔指定毫秒后调⽤clock_12h()*/
> var myTime = setInterval("clock_12h()",1000);
>
> </script> </body> </html>
发布评论