ASP中如何实现实时显示系统时间
3个回答
展开全部
ASP中 <%=now()%> 相当于 <%response.write now()%>
这里是一次性显示加截时的当前时间(是服务器的),是加截时间不是实时,实时时间一般用JS实现,可以现实每秒都更新,真正的实时,而JS读取的是客户端的,也就是浏览者的当前时间。 <input id="input"> <script type="text/javascript"> var in_1 = document.getElementById('input'); function showTime(){ var date = new Date(); var week = date.getDay(); var weekday; switch(week){ case 0: weekday = '星期天';break; case 1: weekday = '星期一';break; case 2: weekday = '星期二';break; case 3: weekday = '星期三';break; case 4: weekday = '星期四';break; case 5: weekday = '星期五';break; case 6: weekday = '星期六';break; } var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); var hour = date.getHours(); var minute = date.getMinutes(); var second = date.getSeconds(); var in_1 = document.getElementById('input'); in_1.value = year + '年' + month + "月" + day + '日'+' ' + weekday + ' ' + hour + ':' + minute + ':' + second; setTimeout(showTime,1000); } showTime(); </script>
这里是一次性显示加截时的当前时间(是服务器的),是加截时间不是实时,实时时间一般用JS实现,可以现实每秒都更新,真正的实时,而JS读取的是客户端的,也就是浏览者的当前时间。 <input id="input"> <script type="text/javascript"> var in_1 = document.getElementById('input'); function showTime(){ var date = new Date(); var week = date.getDay(); var weekday; switch(week){ case 0: weekday = '星期天';break; case 1: weekday = '星期一';break; case 2: weekday = '星期二';break; case 3: weekday = '星期三';break; case 4: weekday = '星期四';break; case 5: weekday = '星期五';break; case 6: weekday = '星期六';break; } var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); var hour = date.getHours(); var minute = date.getMinutes(); var second = date.getSeconds(); var in_1 = document.getElementById('input'); in_1.value = year + '年' + month + "月" + day + '日'+' ' + weekday + ' ' + hour + ':' + minute + ':' + second; setTimeout(showTime,1000); } showTime(); </script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询