1.在页面上引入js

<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
<script src="../scripts/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
	$(function() {
		setInterval(function() {
			$.get("getTime.jsp?timestamp=" + new Date().getTime(), function(
					data) {
				$("#time").html(data);
			});
		}, 1000);
	})
</script>
</head>
<body>
	<div ></div>
</body>

2. 后台getTime.jsp代码

    <%
        Date date = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        out.print(df.format(date));
    %>

如果仅仅显示时间,可单纯通过JavaScript获取本机的时间,自动更新。

相关文章:

  • 2022-02-10
  • 2022-01-02
  • 2022-12-23
  • 2021-08-11
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-03-07
  • 2021-05-24
  • 2021-10-31
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案