当前位置: 代码迷 >> JavaScript >> Javascript页面显示动态时间(解决firefox 年度差异有关问题)
  详细解决方案

Javascript页面显示动态时间(解决firefox 年度差异有关问题)

热度:96   发布时间:2012-09-15 19:09:29.0
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>

?

  相关解决方案