function CurentTime()
{
var now = new Date();
var year = nowgetFullYear(); //年
var month = nowgetMonth() + 1; //月
var day = nowgetDate(); //日
var hh = nowgetHours(); //时
var mm = nowgetMinutes(); //分
var ss = nowgetSeconds(); //秒
var clock = year + "-";
if(month < 10)
clock += "0";
clock += month + "-";
if(day < 10)
clock += "0";
clock += day + " ";
if(hh < 10)
clock += "0";
clock += hh + ":";
if (mm < 10) clock += '0';
clock += mm + ":";
if (ss < 10) clock += '0';
clock += ss;
return(clock);
}
documentwrite(CurentTime());
</script>php动态显示时间,我们需要做的是获取到当前的时间戳,然后在通过innerHTML实时的显示到网页中,toLocaleString就是一个时间戳,按照一定格式显示,这里举个例子:
<table>
<tr bgcolor="#FFFFFF">
<td>当前时间:</td>
<td id="CurrentTime"></td>
<script type="text/javascript">
function changetime(){
var ary = Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
var Timehtml = documentgetElementById('CurrentTime');
var date = new Date();
TimehtmlinnerHTML = ''+datetoLocaleString()+' '+ary[dategetDay()];
}
windowonload = function(){
changetime();
setInterval(changetime,1000);
}
</script>
</tr>
</table>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)