很齐全的HTML时间代码

阅读: 评论:0

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()+"秒";
setTimeout("show()",1000); //设置过1000毫秒就是1秒,调用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 D
ate();
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. <!--   
5. now = new Date()   
6. hour = Hours()   
7. if (hour < 12) {   
8. document.write("现在是: " + LocaleString())   
9. } else if (hour < 18){   
10. document.write("现在是: " + LocaleString())   
11. } else if (hour >= 18) {   
12. document.write("现在是: " + LocaleString())   
13. }   
14. // --></script> 
复制代码
六、浏览器状态栏显示的时钟 如:2:20 P.M. 星期四 在状态栏显示
XML/HTML代码
1.
2.
3. <BODY onLoad="run(); timerONE=window.setTimeout"></BODY> 
4. <SCRIPT LANGUAGE="javascript"> 
5. <!-- Hide   
6. timeID = null;   
7. timeRunning = false;   
8. function stop () {   
9. if(timeRunning)   
10. clearTimeout(timeID);   
11. timeRunning = false;   
12. }   
13. function time () {   
14. tick = new Date();   
15. hours = Hours();   
16. minutes = Minutes();   
17. seconds = Seconds();   
18. day = Day();   
19. month = Month();   
20. date = Date();   
21. year = Year();   
22. current = "" + ((hours >12) ? hours -12 :hours)   
23. current += ((minutes < 10) ? ":0" : ":") + minutes   
24. current += ((seconds < 10) ? ":0" : ":") + seconds   
25. current += (hours >= 12) ? " P.M." : " A.M."   
26. if(day==0){var weekday = " 星期日"}   
27. if(day==1){var weekday = " 星期一"}   
28. if(day==2){var weekday = " 星期二"}   
29. if(day==3){var weekday = " 星期三"}   
30. if(day==4){var weekday = " 星期四"}   
31. if(day==5){var weekday = " 星期五"}   
32. if(day==6){var weekday = " 星期六"}   
33. current +=(weekday)   
34. window.status=current;   
35. timeID = setTimeout("time()",1000);   
36. timeRunning = true;   
37. }   
38. function run(){   
39. stop();     
40. time();   
41. }   
42.   
43. //--> 
44. </SCRIPT> 
复制代码
七、显示最后更新时间代码 如:最后更新时间: 11/27/2008 14:21:04
XML/HTML代码
1.
2.
3. <SCRIPT language=javascript> 
4. <!--hide script from old browsers   
5. document.write("最后更新时间: " + document.lastModified + "")   
6. // end hiding --> 
7. </SCRIPT> 
复制代码
相关帖子
* 征服RIA:函数式编程的原理
收藏 分享
0
* 0
* 0
* 顶
* 踩
本是后山人;偶作前堂客。醉舞经阁半卷书;坐井说天阔。
大志戏功名;海斗量福祸。待到囊中羞涩时;怒指乾坤错。
最快的美国主机,支持支付宝付款,中文面板,无限网站!
分享到: 人人网  QQ空间  百度收藏  开心网  新浪微博  Google书签
lht272
* 发短消息
* 加为好友
lht272 (百科“砖”家) 当前离线
UID
1728
帖子
11276
精华
2
积分
12831
阅读权限
100
来自
山沟
在线时间
2374 小时
注册时间
2009-1-14
最后登录
2010-12-14
个人空间 查看详细资料
版主
Rank: 7Rank: 7Rank: 7
帖子
11276
精华
2
积分
12831
威望
307 
银币
42055 
金币
12647 
来自
山沟
在线时间
2374 小时
注册时间
2009-1-14
优秀版主
2#
发表于 2010-9-10 21:14 | 只看该作者
八、实时走动的数字时钟 如:下午14:22:03
XML/HTML代码
1. <script>
2. function tick() {
3. var hours, minutes, seconds, xfile;
4. var intHours, intMinutes, intSeconds;
5. var today;
6. today = new Date();
7. intHours = Hours();
8. intMinutes = Minutes();
9. intSeconds = Seconds();
10. if (intHours == 0) {
11. hours = "12:";
12. xfile = "午夜";
13. } else if (intHours < 12) {
14. hours = intHours+":";
15. xfile = "上午";
16. } else if (intHours == 12) {
17. hours = "12:";
18. xfile = "正午";
19. } else {
20. intHoursintHours = intHours - 12
21. hours = intHours + ":";
22. xfile = "下午";
23. }
24. if (intMinutes < 10) {
25. minutes = "0"+intMinutes+":";
26. } else {
27. minutes = intMinutes+":";
28. }
29. if (intSeconds < 10) {
30. seconds = "0"+intSeconds+" ";
31. } else {
32. seconds = intSeconds+" ";
33. }
34. timeString = xfile+hours+minutes+seconds;
35. Clock.innerHTML = timeString;
36. window.setTimeout("tick();", 100);
37. }
38. load = tick;
39. </script>
40.
41. <div id="Clock" ></div>
复制代码
九、根据不同的时间显示不同的问候语 如:午安!
XML/HTML代码
方法:在主页中你需要的地方加入以下代码:
1.
2.
3. <script language="LiveScript"> 
4. now = new Date(),hour = Hours()   
5. if(hour < 6){document.write("明天不用上班了吗?")}   
6. else if (hour < 8){document.write("全新的一天!")}   
7. else if (hour < 12){document.write("早安!")}   
8. else if (hour < 14){document.write("外面太阳大吗?")}   
9. else if (hour < 18){document.write("午安!")}   
10. else if (hour < 22){document.write("晚上好!")}   
11. else if (hour < 24){document.write("夜深了! 要注意身体呀! 祝你做个好梦!")}   
12. // --> 
13. </script> 
复制代码
说明,可以自行修改出更好更多的问候语!
十、显示年月日星期及农历的月和日 如:2008年11月27日 星期四 农历 10月30日
第一步:将一下代码保存为.JS文件
XML/HTML代码
1. <!--
2. function CalConv()
3. {
4. FIRSTYEAR = 1998;
5. LASTYEAR = 2031;
6.
7. today = new Date();
8. SolarYear = FullYear();
9. SolarMonth = Month() + 1;
10. SolarDate = Date();
11. Weekday = Day();
12. LunarCal = [
13. new tagLunarCal( 27, 5, 3, 43, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1 ),
14. new tagLunarCal( 46, 0, 4, 48, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1 ), /* 88 */
15. new tagLunarCal( 35, 0, 5, 53, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1 ), /* 89 */
16. new tagLunarCal( 23, 4, 0, 59, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ),
17. new tagLunarCal( 42, 0, 1, 4, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ),
18. new tagLunarCal( 31, 0, 2, 9, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0 ),
19. new tagLunarCal( 21, 2, 3, 14, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1 ), /* 93 */
20. new tagLunarCal( 39, 0, 5, 20, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1 ),
21. new tagLunarCal( 28, 7, 6, 25, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1 ),
22. new tagLunarCal( 48, 0, 0, 30, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1 ),
23. new tagLunarCal( 37, 0, 1, 35, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1 ), /* 97 */
24. new tagLunarCal( 25, 5, 3, 41, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 ),
25. new tagLunarCal( 44, 0, 4, 46, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 ),
26. new tagLunarCal( 33, 0, 5, 51, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ),
27. new tagLunarCal( 22, 4, 6, 56, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 ), /* 101 */
28. new tagLunarCal( 40, 0, 1, 2, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 ),
29. new tagLunarCal( 30, 9, 2, 7, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 ),
30. new tagLunarCal( 49, 0, 3, 12, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1 ),
31. new tagLunarCal( 38, 0, 4, 17, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0 ), /* 105 */
32. new tagLunarCal( 27, 6, 6, 23, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1 ),
33. new tagLunarCal( 46, 0, 0, 28, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0 ),
34. new tagLunarCal( 35, 0, 1, 33, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0 ),
35. new

本文发布于:2023-05-06 03:51:01,感谢您对本站的认可!

本文链接:https://patent.en369.cn/patent/1/89678.html

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

标签:代码   显示   时间   调用   函数   功名   加入   面板
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 369专利查询检索平台 豫ICP备2021025688号-20 网站地图