显示当时时间年月日星期 精确到秒源代码

  • A+
所属分类:有趣源码
  1. <SCRIPT?type=text/javascript>
  2. window.onload?=?function()?{
  3. ?startTime();
  4. }
  5. function?startTime()?{
  6. ?try{
  7. ??var?today?=?new?Date();
  8. ??var?year?=?today.getFullYear();
  9. ??var?month?=?checkNum(today.getMonth()+1);
  10. ??var?date?=?checkNum(today.getDate());
  11. ??var?day?=?today.getDay();
  12. ??var?hour?=?checkNum(today.getHours());
  13. ??var?minute?=?checkNum(today.getMinutes());
  14. ??var?second?=?checkNum(today.getSeconds());
  15. ??switch(day)?{
  16. ???case?1:
  17. ????day?=?"一";
  18. ????break;
  19. ???case?2:
  20. ????day?=?"二";
  21. ????break;
  22. ???case?3:
  23. ????day?=?"三";
  24. ????break;
  25. ???case?4:
  26. ????day?=?"四";
  27. ????break;
  28. ???case?5:
  29. ????day?=?"五";
  30. ????break;
  31. ???case?6:
  32. ????day?=?"六";
  33. ????break;
  34. ???case?7:
  35. ????day?=?"日";
  36. ????break;
  37. ??}
  38. ??var?fullTime?=?year+"年"+month+"月"+date+"日"+"星期"+day+"?"+hour+":"+minute+":"+second;
  39. ??document.getElementById("showTime").innerHTML?=?fullTime;
  40. ??setInterval('startTime()',?1000);
  41. ?}
  42. ?catch(e)?{
  43. ??alert(e.description);
  44. ?}
  45. }
  46. function?checkNum(num)?{
  47. ?if(num<10)?{
  48. ??num?=?"0"+num;
  49. ?}
  50. ?return?num;
  51. }
  52. </SCRIPT>
  53. <div?id=showTime></div>

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: