很齐全的HTML时间代码

<script>
function show(){
var date = new Date(); //日期对象
var now = "";
now = FullYear()+"年"; //读英文就行了
now = now + (Month()+1)+"月"; //取月的时候取的是当前月-1如果想取当前月+1就可以了
now = now + Date()+"日";
now = now + Hours()+"时";
now = now + Minutes()+"分";
now = now + Seconds()+"秒";
调用show方法
}
</script>
<body onload="show()"> <!-- 网页加载时调用一次以后就自动调用了-->
<div id="nowDiv"></div>
</body>
实时走动的数字时钟如:下午14:15:00
第一步:在<body></body>区域加入以下代码
XML/HTML代码
<script>
function tick() {
var hours, minutes, seconds, xfile;
var intHours, intMinutes, intSeconds;
var today;
today = new Date();
intHours = Hours();
intMinutes = Minutes();
intSeconds = Seconds();
if (intHours == 0) {
hours = "12:";
xfile = "午夜";
} else if (intHours < 12) {
hours = intHours+":";
xfile = "上午";
} else if (intHours == 12) {
hours = "12:";
xfile = "正午";
} else {
intHoursintHours = intHours - 12
hours = intHours + ":";
xfile = "下午";
}
if (intMinutes < 10) {
minutes = "0"+intMinutes+":";
} else {
minutes = intMinutes+":";
}
if (intSeconds < 10) {
seconds = "0"+intSeconds+" ";
} else {
seconds = intSeconds+" ";
}
timeString = xfile+hours+minutes+seconds;
Clock.innerHTML = timeString;
window.setTimeout("tick();", 100);
}
</script>
复制代码
第二步.将下面的代码加入html文件任意需要的地方
1. <div id="Clock" align="center" ></div> 复制代码
你可以自行更改样式!
二、显示年月日格式的时间代码如:2008年11月27日星期四
XML/HTML代码
1. <script language=javascript>
2. today=new Date();
3. function initArray(){
4. this.length=initArray.arguments.length
5. for(var i=0;i<this.length;i++)
6. this[i+1]=initArray.arguments[i] }
7. var d=new initArray(
8. "星期日",
9. "星期一",
10. "星期二",
11. "星期三",
12. "星期四",
13. "星期五",
14. "星期六");
15. document.write(
16. "<font color=##000000 style='font-size:9pt;font-family: 宋体'> ",
17. Year(),"年",
18. Month()+1,"月",
19. Date(),"日",
20. Day()+1],
21. "</font>" );
22. </script>
复制代码
三、显示日期,星期,时间格式的代码如:2008年11月27日星期四下午2:17:36 XML/HTML代码
1.
2.
3. <SCRIPT language=JavaScript>
4. today=new Date();
5. function initArray(){
6.    this.length=initArray.arguments.length
7.    for(var i=0;i<this.length;i++)
8.    this[i+1]=initArray.arguments[i]  }
9.    var d=new initArray(
10.      "星期日",
11.      "星期一",
12.      "星期二",
13.      "星期三",
14.      "星期四",
15.      "星期五",
16.      "星期六");
17. document.write(
18.      "<font color=#ecc1c1 style='font-size:9pt;font-family: 宋体'> ",
19.      Year(),"年",
20.      Month()+1,"月",
21.      Date(),"日",
22.      Day()+1],
23.      "</font>" );
24.            </SCRIPT>
25.                </TD>
26.                <TD class=bai align=left width=95>
27.                  <SCRIPT language=JavaScript>
28.
29. function tick() {
30. var hours, minutes, seconds, xfile;
31. var intHours, intMinutes, intSeconds;
32. var today;
33. today = new Date();
34. intHours = Hours();
35. intMinutes = Minutes();
36. intSeconds = Seconds();
37. if (intHours == 0) {
38. hours = "12:";
39. xfile = "午夜";
40. } else if (intHours < 12) {
41. hours = intHours+":";
42. xfile = "上午";
43. } else if (intHours == 12) {
44. hours = "12:";
45. xfile = "正午";
46. } else {
47. intHours = intHours - 12
48. hours = intHours + ":";
49. xfile = "下午";
50. }
51. if (intMinutes < 10) {
52. minutes = "0"+intMinutes+":";
53. } else {
54. minutes = intMinutes+":";
55. }
56. if (intSeconds < 10) {
57. seconds = "0"+intSeconds+" ";
58. } else {
59. seconds = intSeconds+" ";
60. }
61. timeString = xfile+hours+minutes+seconds;
62. Clock.innerHTML = timeString;
63. window.setTimeout("tick();", 100);
64. }
65. load = tick;
66. </SCRIPT>
67. <DIV id=Clock align=center></DIV>  复制代码
四、显示来访者的停留时间如:停留时间: 00:15
XML/HTML代码
1.
2.
3. <script language="javascript">
4. var ap_name = navigator.appName;
5. var ap_vinfo = navigator.appVersion;
6. var ap_ver = parseFloat(ap_vinfo.substring(0,ap_vinfo.indexOf('(')));
7.
8. var time_start = new Date();
9. var clock_start = Time();
10. var dl_ok=false;
11.
12. function init ()
13. {
14. if(ap_name=="Netscape" && ap_ver>=3.0)
15. dl_ok=true;
16. return true;
17. }
18.
19. function get_time_spent ()
20. {
21. var time_now = new Date();
22. return((Time() - clock_start)/1000);
23. }
24.
25. function show_secs () // show the time user spent on the side
26. {
27. var i_total_secs = und(get_time_spent());
28. var i_secs_spent = i_total_secs % 60;
29. var i_mins_spent = und((i_total_secs-30)/60);
30. var s_secs_spent = "" + ((i_secs_spent>9) ? i_secs_spent : "0" + i_secs_spent);
31. var s_mins_spent = "" + ((i_mins_spent>9) ? i_mins_spent : "0" + i_mins_spent);
32. document.fm0.time_spent.value = s_mins_spent + ":" + s_secs_spent;
33. window.setTimeout('show_secs()',1000);
34. }
35.
36. // -->
37. </script>
38. <FORM name="fm0" onSubmit="0"><FONT COLOR="#6060FF">停留时间:
39. </FONT><INPUT type="text" name="time_spent" size=7 onFocus="this.blur()"></FORM>
复制代码
而且还要在你主页源文件<body>中加入下面的代码
1. <BODY onLoad="init(); window.setTimeout('show_secs()',1);">
复制代码
五、显示当前日期与时间如:现在是: 2008年11月27日 14:18:59 时间不走动
XML/HTML代码
1.
2.
3. <script language="javascript">
4. <!--

本文发布于:2024-09-20 13:53:55,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/2/88672.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:代码   调用   时间
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议