日期:2014-05-16  浏览次数:20373 次

Javascript页面显示动态时间(解决firefox 年度差异问题)
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
      %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>显示时间</title>

<script type="text/javascript">

function getTime(){
         var time = new Date();
         var year = time.getYear();
          if(navigator.userAgent.indexOf("Firefox")>0){
                    year=year+1900;
                }
 /*判断是否为Firefox浏览器 ,如果是,年度加上1900得到正确年份  */
         var month = time.getMonth();
         var day = time.getDate();
         var hour = time.getHours();
         var minute = time.getMinutes();
         var second = time.getSeconds();
         return year+"-"+month+"-"+day+"  "+hour+":"+minute+":"+second;
 }

 function setTime(){
             var timeStr=getTime();
             document.getElementById('time').innerHTML = timeStr;
             setTimeout(setTime,1000);
  }
</script>
</head>
<body onload="setTime()">
       <h3>
            <span>Time:</span><span id="time"></span>
        </h3>

</body>
</html>

?