欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js+html获取系统当前时间

程序员文章站 2022-06-17 13:27:45
本文实例为大家分享了html获取系统当前时间的具体代码,供大家参考,具体内容如下

本文实例为大家分享了html获取系统当前时间的具体代码,供大家参考,具体内容如下

<html>
<head>
<style>
td {
font-size: 12px; color: #ffffff; font-family: verdana, arial, helvetica, sans-serif
}
</style>
<script language=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;
</script>
</head>
<body leftmargin=0 topmargin=0 marginwidth="0" marginheight="0">
<table cellspacing=0 cellpadding=0 width="100%" border=0>
<tr bgcolor=#73a3d4 height=40>
<td nowrap align=right width=209 ><span id="clock"></span></td>
</tr>
</table>
</body>
</html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。