|
[watermark][html]
<p id="cs">这里将显示时间</p><!--设置p标签,(不明白的查看html相关资料)并设置其id为cs,-->
<script>
function thetime(){ //定义一个名为thetime的函数
var theday = new Date() //定义一个日期对象(获取系统当前日期:例:Thu Nov 30 16:33:05 UTC+0800 2006)
var theyear = theday.getYear() //获取日期里的年份,如上的2006
var themonth = theday.getMonth()+1 //获取月份
var thedays = theday.getDate() //获取当前日
var thehours = theday.getHours() //获取小时
var theminutes = theday.getMinutes() //获取分
var theseconds = theday.getSeconds() //获取秒
var tt = ("现在是:"+theyear+"年"+themonth+"月"+thedays+"日"+thehours+"时"+theminutes+"分"+theseconds+"秒")//显示时间字符串
document.getElementById("cs").innerHTML=tt //在id为cs的标签中输入显示时间的字符串
setTimeout("thetime()",1000) //设置多长时间执行一次thetime函数,单位为毫秒,即1000=1秒
}
thetime();
</script>
[/html][/watermark] |
|