返回
心录历程
首页
JS在网页上显示当前日期和时间
2014-05-01 03:06:04 -0400
此代码
仅
供
参
考
代码说明
一个基于JavaScript日期时间特效,在网页上显示当前的日期和时间,本效果还做了一些美化,在网页的右上角显示,自动获取当前的windows时间,秒在不停走动,新手只需复制本代码保存成HTML,即可上传到服务器测试预览了。
html代码
JavaScript
function tick() { var years,months,days,hours, minutes, seconds; var intYears,intMonths,intDays,intHours, intMinutes, intSeconds; var today; today = new Date(); //系统当前时间 intYears = today.getFullYear(); //得到年份,getFullYear()比getYear()更普适 intMonths = today.getMonth() + 1; //得到月份,要加1 intDays = today.getDate(); //得到日期 intHours = today.getHours(); //得到小时 intMinutes = today.getMinutes(); //得到分钟 intSeconds = today.getSeconds(); //得到秒钟 years = intYears + "-"; if(intMonths < 10 ){ months = "0" + intMonths +"-"; } else { months = intMonths +"-"; } if(intDays < 10 ){ days = "0" + intDays +" "; } else { days = intDays + " "; } if (intHours == 0) { hours = "00:"; } else if (intHours < 10) { hours = "0" + intHours+":"; } else { hours = intHours + ":"; } if (intMinutes < 10) { minutes = "0"+intMinutes+":"; } else { minutes = intMinutes+":"; } if (intSeconds < 10) { seconds = "0"+intSeconds+" "; } else { seconds = intSeconds+" "; } timeString = years+months+days+hours+minutes+seconds; Clock.innerHTML = timeString; window.setTimeout("tick();", 1000); } window.onload = tick;
代码演示
【本站仅供参考,版权归原作者所有】
«Newer
Older»
Comment:
Name:
Back to home
Subscribe
|
Register
|
Login
|
N