`
王牌海盗
  • 浏览: 237414 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

经典时间代码集锦

阅读更多

实时走动的数字时钟

<script>
function tick() {
var hours, minutes, seconds, xfile;
var intHours, intMinutes, intSeconds;
var today;
today = new Date();
intHours = today.getHours();
intMinutes = today.getMinutes();
intSeconds = today.getSeconds();
if (intHours == 0) {
hours = "12:";
xfile = "午夜";
} else if (intHours < 12) {
hours = intHours+":";
xfile = "上午";
} else if (intHours == 12) {
hours = "12:";
xfile = "正午";
} else {
intHours = 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);
}
window.onload = tick;
</script>

第二步.将下面的代码加入html文件任意需要的地方

你可以自行更改样式!

 显示年月日格式的时间代码


<script language=javascript>
today=new Date();
function initArray(){
this.length=initArray.arguments.length
for(var i=0;i<this.length;i++)
this[i+1]=initArray.arguments[i] }
var d=new initArray(
"星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六");
document.write(
"<font color=##000000 style='font-size:9pt;font-family: 宋体'> ",
today.getYear(),"年",
today.getMonth()+1,"月",
today.getDate(),"日",
d[today.getDay()+1],
"</font>" ); 

 显示日期,星期,时间格式的代码


<script language="javascript">
<!---
today=new Date();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
var timevalue = "<FONT COLOR=black>" + ((hours >12) ? hours -12 :hours); timevalue += ((minutes < 10) ? "<BLINK>

<FONT COLOR=black>:</FONT></BLINK>0" : "<BLINK><FONT COLOR=black>:</FONT></BLINK>") + minutes+"</FONT></FONT>";

timevalue += (hours >= 12) ? "<FONT COLOR=blue><I><B>pm</B></I></FONT>" : "<FONT COLOR=blue><B><I>am</I></B></FONT>";
function initArray(){
this.length=initArray.arguments.length
for(var i=0;i<this.length;i++)
this[i+1]=initArray.arguments[i] }
var d=new initArray("<font color=RED>星期日","<font color=black>星期一","<font color=black>星期二","<font color=black>星期

三","<font color=black>星期四","<font color=black>星期五","<font color=red>星期六"); document.write

("<font color=black>",today.getYear(),"<font color=black>年","<font color=black>",today.getMonth()+1,"<font color=black>

月","<font color=black>",today.getDate(),"<font color=black>日 </FONT>",d[today.getDay()+1]," ",timevalue); //-->
</script> 

 显示来访者的停留时间


<script language="javascript">
var ap_name = navigator.appName;
var ap_vinfo = navigator.appVersion;
var ap_ver = parseFloat(ap_vinfo.substring(0,ap_vinfo.indexOf('(')));

var time_start = new Date();
var clock_start = time_start.getTime();
var dl_ok=false;

function init ()
{
if(ap_name=="Netscape" && ap_ver>=3.0)
dl_ok=true;
return true;
}

function get_time_spent ()
{
var time_now = new Date();
return((time_now.getTime() - clock_start)/1000);
}

function show_secs () // show the time user spent on the side
{
var i_total_secs = Math.round(get_time_spent());
var i_secs_spent = i_total_secs % 60;
var i_mins_spent = Math.round((i_total_secs-30)/60);
var s_secs_spent = "" + ((i_secs_spent>9) ? i_secs_spent : "0" + i_secs_spent);
var s_mins_spent = "" + ((i_mins_spent>9) ? i_mins_spent : "0" + i_mins_spent);
document.fm0.time_spent.value = s_mins_spent + ":" + s_secs_spent;
window.setTimeout('show_secs()',1000);
}

// -->
</script>
<FORM name="fm0" onSubmit="0"><FONT COLOR="#6060FF">停留时间:
</FONT><INPUT type="text" name="time_spent" size=7 onFocus="this.blur()"></FORM>

第二步:在你主页源文件<body>中加入下面代码的兰色部分

<BODY onLoad="init(); window.setTimeout('show_secs()',1);">

 显示当前日期与时间的格式


<script language="javascript">
<!--
now = new Date()
hour = now.getHours()
if (hour < 12) {
document.write("现在是: " + now.toLocaleString())
} else if (hour < 18){
document.write("现在是: " + now.toLocaleString())
} else if (hour >= 18) {
document.write("现在是: " + now.toLocaleString())
}
// --></script>

 浏览器状态栏显示的时钟

<BODY onLoad="run(); timerONE=window.setTimeout"></BODY>
<SCRIPT LANGUAGE="javascript">
<!-- Hide
timeID = null;
timeRunning = false;
function stop () {
if(timeRunning)
clearTimeout(timeID);
timeRunning = false;
}
function time () {
tick = new Date();
hours = tick.getHours();
minutes = tick.getMinutes();
seconds = tick.getSeconds();
day = tick.getDay();
month = tick.getMonth();
date = tick.getDate();
year = tick.getYear();
current = "" + ((hours >12) ? hours -12 :hours)
current += ((minutes < 10) ? ":0" : ":") + minutes
current += ((seconds < 10) ? ":0" : ":") + seconds
current += (hours >= 12) ? " P.M." : " A.M."
if(day==0){var weekday = " 星期日"}
if(day==1){var weekday = " 星期一"}
if(day==2){var weekday = " 星期二"}
if(day==3){var weekday = " 星期三"}
if(day==4){var weekday = " 星期四"}
if(day==5){var weekday = " 星期五"}
if(day==6){var weekday = " 星期六"}
current +=(weekday)
window.status=current;
timeID = setTimeout("time()",1000);
timeRunning = true;
}
function run(){
stop();
time();
}

//-->
</SCRIPT>

 显示最后更新时间代码


<SCRIPT language=javascript>
<!--hide script from old browsers
document.write("最后更新时间: " + document.lastModified + "")
// end hiding -->
</SCRIPT>实时走动的数字时钟

<script>
function tick() {
var hours, minutes, seconds, xfile;
var intHours, intMinutes, intSeconds;
var today;
today = new Date();
intHours = today.getHours();
intMinutes = today.getMinutes();
intSeconds = today.getSeconds();
if (intHours == 0) {
hours = "12:";
xfile = "午夜";
} else if (intHours < 12) {
hours = intHours+":";
xfile = "上午";
} else if (intHours == 12) {
hours = "12:";
xfile = "正午";
} else {
intHours = 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);
}
window.onload = tick;
</script>

<div id="Clock" style="font-size: 20; color:#000000"></div>

 根据不同的时间显示不同的问候语

方法:在主页中你需要的地方加入以下代码:

<script language="LiveScript">
now = new Date(),hour = now.getHours()
if(hour < 6){document.write("明天不用上班了吗?")}
else if (hour < 8){document.write("全新的一天!")}
else if (hour < 12){document.write("早安!")}
else if (hour < 14){document.write("外面太阳大吗?")}
else if (hour < 18){document.write("午安!")}
else if (hour < 22){document.write("晚上好!")}
else if (hour < 24){document.write("夜深了! 要注意身体呀! 祝你做个好梦!")}
// -->
</script>

说明,可以自行修改出更好更多的问候语!

 一个很酷的透明时钟代码

方法:在页面中你需要的地方加入下面的代码

<STYLE type=text/css>
BODY {COLOR: #000000; FONT-FAMILY: "宋体"; FONT-SIZE: 9pt; LINE-HEIGHT: 13pt}
TD {COLOR: #000000; FONT-FAMILY: "宋体"; FONT-SIZE: 9pt; LINE-HEIGHT: 13pt}
A:visited {COLOR: #000080;text-decoration:none}
a:link        { text-decoration:none }
a:hover       { text-decoration:underline }
.f12 {font-size:12px;}
.f13 {font-size:14.9px; LINE-HEIGHT: 120%}
.f24 {font-size:24px;LINE-HEIGHT: 120%}
.f14 {font-size:14.9px; LINE-HEIGHT: 170%}
</STYLE>
<script LANGUAGE="javascript">
Zp=670;H='....';H=H.split('');M='.....';M=M.split('');S='......';S=S.split('');Yp=0;Xp=0;Yb=8;Xb=8;d_=12;

ns=(document.layers)?1:0;fCol='222222';sCol='ff0000';mCol='0000ee';hCol='green';if (ns){dgts='1 2 3 4 5 6 7 8 9 10 11 12';

dgts=dgts.split(' ');for (i=0;i<d_;i++){document.write('<layer name=nsDigits'+i+' top=0 left=0 height=30 width=30>

<center><font face=Arial,Verdana size=1 color='+fCol+'>'+dgts[i]+'</font></center></layer>');}for (i=0;i<M.length;i++)

{document.write('<layer name=ny'+i+' top=0 left=0 bgcolor='+mCol+' clip="0,0,2,2"></layer>');}for (i=0;i<H.length;i++)

{document.write('<layer name=nz'+i+' top=0 left=0 bgcolor='+hCol+' clip="0,0,2,2"></layer>');}for (i=0;i<S.length;i++)

{document.write('<layer name=nx'+i+' top=0 left=0 bgcolor='+sCol+' clip="0,0,2,2"></layer>');}}else{document.write('

<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');for (i=1;i<d_+1;i++){document.write

('<div id="ieDigits" style="position:absolute;top:0px;left:0px;width:30px;height:30px;font-family:Arial,Verdana;font-size:

10px;color:'+fCol+';text-align:center;padding-top:10px">'+i+'</div>');}document.write('</div></div>');document.write

('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');for (i=0;i<M.length;i++){document.write

('<div id=y style="position:absolute;width:2px;height:2px;font-size:2px;background:'+mCol+'"></div>');}document.write('</div>

</div>');document.write('</div></div>');document.write('<div style="position:absolute;top:0px;left:0px">

<div style="position:relative">');for (i=0;i<H.length;i++){document.write

('<div id=z style="position:absolute;width:2px;height:2px;font-size:2px;background:'+hCol+'"></div>');}document.write('</div>

</div>');document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');for (i=0;i

<S.length;i++){document.write('<div id=x style="position:absolute;width:2px;height:2px;font-size:2px;background:'+sCol+'">

</div>');}document.write('</div></div>');}function clock(){time=new Date ();secs=time.getSeconds();sec=-1.57+Math.PI*secs/

30;mins=time.getMinutes();min=-1.57+Math.PI*mins/30;hr=time.getHours();hrs=-1.57+Math.PI*hr/6+Math.PI*parseInt(time.getMinutes

())/360;if (ns){Yp=window.pageYOffset+window.innerHeight-60;Xp=80;}else

{Yp=document.body.scrollTop+window.document.body.clientHeight-60;Xp=document.body.scrollLeft+60;}if (ns){for (i=0;i<d_;++i)

{document.layers["nsDigits"+i].top=Yp-5+40*Math.sin(-0.49+d_+i/1.9);document.layers["nsDigits"+i].left=Xp-15+40*Math.cos(-0.49

+d_+i/1.9);}for (i=0;i<S.length;i++){document.layers["nx"+i].top=Yp+i*Yb*Math.sin(sec);document.layers

["nx"+i].left=Xp+i*Xb*Math.cos(sec);}for (i=0;i<M.length;i++){document.layers["ny"+i].top=Yp+i*Yb*Math.sin(min);document.layers

["ny"+i].left=Xp+i*Xb*Math.cos(min);}for (i=0;i<H.length;i++){document.layers["nz"+i].top=Yp+i*Yb*Math.sin(hrs);document.layers

["nz"+i].left=Xp+i*Xb*Math.cos(hrs);}}else{for (i=0;i<d_;++i){ieDigits[i].style.pixelTop=Yp-15+40*Math.sin(-0.49+d_+i/

1.9);ieDigits[i].style.pixelLeft=Xp-14+40*Math.cos(-0.49+d_+i/1.9)+Zp;}for (i=0;i<S.length;i++){x

[i].style.pixelTop=Yp+i*Yb*Math.sin(sec);x[i].style.pixelLeft=Xp+i*Xb*Math.cos(sec)+Zp;}for (i=0;i<M.length;i++){y

[i].style.pixelTop=Yp+i*Yb*Math.sin(min);y[i].style.pixelLeft=Xp+i*Xb*Math.cos(min)+Zp;}for (i=0;i<H.length;i++){z

[i].style.pixelTop=Yp+i*Yb*Math.sin(hrs);z[i].style.pixelLeft=Xp+i*Xb*Math.cos(hrs)+Zp;}}setTimeout('clock()', 50);}


if (document.layers || document.all) {window.onload=clock;}
window.onload=clock;
</script>

分享到:
评论

相关推荐

    MATLAB 经典程序源代码大全.rar

    MATLAB 经典程序源代码大全,。其中函括 1、中国大学生数学建模竞赛题解 2、演示程序 3、微积分和微分方程 4、图形 5、随机模拟和统计分析 6、数学规划 7、数据拟合 8、离散优化 9、方程求根 10、时间序列分析以及...

    C#入门经典代码

    《C#入门经典》(Karli Waston和Christian Nagel著,齐立波等译)作为C sharp学习的经典之作,是初学者学习的不二选择。这里集合了该书全部的程序代码,省去了你长时间输入的麻烦。希望能帮助你的学习

    C++经典代码大全

    这本书中所论述的技术不仅填补了初级与高级编程技术之间的空白,而且也为程序员们提供了一个有关编程技巧的信息来源。...可以说,无论是什么背景的读者,阅读这本书都有助于在更短的时间内、更容易地写出更好的程序。

    整理的数学建模相关算法的MATLAB代码以及相应算法比较经典的参考文献(遗传算法、时间序列、向量机等等).zip

    整理的数学建模相关算法的MATLAB代码以及相应算法比较经典的参考文献(遗传算法、时间序列、向量机等等) 整理的数学建模相关算法的MATLAB代码以及相应算法比较经典的参考文献(遗传算法、时间序列、向量机等等) ...

    c语言经典代码(针对初学者)

    2.c模拟weindow下getch.c某月天数.c逆序.c逆序四位整数.c排序.c判断某个...时间类.c实现库函数.c实现薪酬计算.c实现栈.c数组从大到小从哦你笑道大排序.c数组最大最小值.c顺序表.c四个数中最大数.c素数.c未完成剔除数组...

    ExcelVBA编程常用代码.pdf

    得到当前日期及时间 ```vba MsgBox Date & Chr(13) & Time ``` 保护工作簿 ```vba ActiveSheet.Protect ``` 取消保护工作簿 ```vba ActiveSheet.Unprotect ``` 给活动工作表改名 ```vba ActiveSheet.Name = ...

    安卓项目开发经典实例代码_学习好样例

    安卓项目开发经典实例代码,不可多得好样例.大大缩短学习时间

    【Jquery经典特效14】jQuery动画垂直时间轴特效代码

    【Jquery经典特效14】jQuery动画垂直时间轴特效代码

    PB9.0精彩编程源代码百例

    想要学习PB的新童鞋有福了,经过本人一个月来学习过程中下载使用过的众多PB...想想这段时间下载那么多代码,那么多无法使用,我强烈向大家推荐这套98例源代码,相信她肯定可以帮到PB新朋友,绝对值得下载、珍藏!!!

    NET项目经典源代码

    的方式的覅等级科技科的即可可idhjfdshshf科的身份上帝哦方式的会计法上课的福利科技方可实际开发技术开发及考试及开发及时间

    MATLAB 经典程序源代码大全

    本资源经过数模之后总结的一些经典代码。其中函括 1、中国大学生数学建模竞赛题解 2、演示程序 3、微积分和微分方程 4、图形 5、随机模拟和统计分析 6、数学规划 7、数据拟合 8、离散优化 9、方程求根 10、时间序列...

    [经典]MATLAB 程序源代码合集.zip

    经典的MATLAB程序设计源代码: 车牌识别系统设计源码 方程求根 离散优化 数据拟合 数学规划 图形 微积分和微分方程 演示程序 大学生数学建模竞赛题解 随机模拟和统计分析 时间序列分析以及递推关系的作图分析等等

    js日期时间代码.zip

    js日期时间代码是一款经典的日期时间脚本,时间日期可任选择,方便输入。  js日期时间代码演示图: 点击查看演示:

    JavaScript入门经典(第3版) 附书源代码.rar

    JavaScript入门经典(第3版)书源代码作者: 麦可匹克 出版社: 清华大学出版社 第1章 eb与JavaScript概述1.1 JavaScript简介1.2 创建JavaScriptWeb应用程序所需的工具1.3 (script)标记:第一个简单的JavaScript程序...

    批处理程序代码及p处理游戏代码集合

    批处理程序代码及p处理游戏代码集合.rar 很经典的批处理

    [代码大全2中文版(完整清晰版)].part01 代码大全2中文版

    代码大全(第二版)是著名IT畅销书作者Steve McConnell十一年前的经典著作的全新演绎:第二版不是第一版的简单修订增补,而是完全进行了重写;增加了很多与时俱进的内容。这也是一本完整的软件构建手册,涵盖了软件...

    .NET代码生成器(太经典了,用了很久了)

    是一款为C#数据库程序员设计的自动代码生成器,Codematic 生成的代码基于面向对象的思想和三层架构设计,结合了Petshop中经典的思想和设计模式,融入了工厂模式,反射机制等等一些思想。采用Model+DAL +BLL+Web 的...

    恶意代码分析实战

    详尽,经典——每一位认真学习过《恶意代码分析实战》的读者,必将在恶意代码分析的专业技能上获得巨大的提升。 《恶意代码分析实战》是业内公认的迄今为止优秀的一本恶意代码分析指南,《恶意代码分析实战》也是每...

    VB排序代码(7种经典排序算法已优化)

    VB排序代码---7种经典排序算法已优化---可记录各种排序的时间及循环次数。

    代码大全(经典教材).pdf

    代码大全(经典教材).pdf 计算机实用软件技术系列丛书 软件开发人员必备工具书 Code Complete 代码大全 Steve McConnell 著 天奥 译 熊可宜 校 学苑出版社 目 录 第一章 欢迎进入软件创建世界⋯⋯⋯⋯⋯⋯...

Global site tag (gtag.js) - Google Analytics