Chinaunix首页 | 论坛 | 博客
  • 博客访问: 341366
  • 博文数量: 329
  • 博客积分: 2633
  • 博客等级: 少校
  • 技术积分: 3633
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-22 15:43
文章分类

全部博文(329)

文章存档

2013年(244)

2012年(46)

2011年(39)

我的朋友

分类: 系统运维

2012-03-02 20:12:00

界面:

页面中:

  1. <td colspan="2" class="word_white" id="Time">&nbsp;<script language="javascript">ShowDate(Time);</script></td>
  2.         <td width="10%" class="word_white" id="Time2">&nbsp;<script language="javascript">ShowTime(Time2);</script></td>

DateTime2.js中:

 

  1. // 显示日期和时间-------NQ

  2. function ShowDate(Elements)
  3. {
  4.         var temp;
  5.         var datetime = new Date();
  6.         var year = datetime.getYear();
  7.         var month = datetime.getMonth() + 1;
  8.         var date = datetime.getDate();
  9.         var day = datetime.getDay();
  10.         temp = year+"年"+month+"月"+date+"日 ";
  11.         switch (day)
  12.         {
  13.             case 0:
  14.                 temp = temp+"星期日";
  15.                 break;
  16.             case 1:
  17.                 temp = temp+"星期一";
  18.                 break;
  19.             case 2:
  20.                 temp = temp+"星期二";
  21.                 break;
  22.             case 3:
  23.                 temp = temp+"星期三";
  24.                 break;
  25.             case 4:
  26.                 temp = temp+"星期四";
  27.                 break;
  28.             case 5:
  29.                 temp = temp+"星期五";
  30.                 break;
  31.             case 6:
  32.                 temp = temp+"星期六";
  33.                 break;
  34.         }
  35.         Elements.innerHTML = temp;
  36. }
  37. function ShowTime(Elements)
  38. {
  39.         var temp = "";
  40.         var datetime = new Date();
  41.         var hour = datetime.getHours();
  42.         var minu = datetime.getMinutes();
  43.         var seco = datetime.getSeconds();
  44.         if(hour < 10)
  45.         hour ="0" + hour;
  46.         if(minu < 10)
  47.         minu ="0" + minu;
  48.         if(seco < 10)
  49.         seco ="0" + seco;
  50.         temp = temp+" "+hour+":"+minu+":"+seco+" ";
  51.         if(hour >= 0 && hour < 5)
  52.         temp = temp + "零晨好"
  53.         if(hour >= 5 && hour < 8)
  54.         temp = temp + "早上好"
  55.         if(hour >= 8 && hour < 11)
  56.         temp = temp + "上午好"
  57.         if(hour >= 11 && hour < 13)
  58.         temp = temp + "中午好"
  59.         if(hour >= 13 && hour < 17)
  60.         temp = temp + "下午好"
  61.         if(hour >= 17 && hour < 24)
  62.         temp = temp + "晚上好"
  63.         Elements.innerHTML = temp; //这个Elements代表(表格)的id

  64.         window.setTimeout("ShowTime(" + Elements.id + ")",1000) //这里Elements.name或Elements.id不是Elements

  65.         
  66. }

 

 

 

 

阅读(2374) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~