时间
设计一个时钟
1 function startTime() { 2 var date = new Date(); 3 var h = date.getHours(); 4 var m = date.getMinutes(); 5 var s = date.getSeconds(); 6 m = checkTime(m) 7 s = checkTime(s) 8 document.getElementById('txt').innerHTML = h + ":" + m + ":" + s 9 t = setTimeout('startTime()', 500) 10 } 11 function checkTime(i) { 12 if (i < 10) { 13 i = "0" + i 14 } 15 return i 16 }
1 <body onload="startTime()"> 2 <div id="txt"></div>
求出两个页面跳转的时间差
1 //a.jsp 2 Date d = new Date(); 3 long s = d.getTime(); //求出初始时间 4 session.setAttribute("start", s); //sesion 对象进行存储 5 6 7 8 //b.jsp 9 Date now = new Date(); 10 long n = now.getTime(); //获取此刻时间 11 String strStart = (String)session.getAttribute("start"); 12 //获取出时间 13 long str = LONG.parseLong(strStart);//object对象进行转换 14 long difer = n - str; //求取时间差