gpt4 book ai didi

java - JSP - 如何获得以毫秒为单位不断更新的时间

转载 作者:行者123 更新时间:2023-11-30 04:27:19 24 4
gpt4 key购买 nike

我正在尝试为自己编写一个示例 JSP 页面(对 jsp 非常陌生),并且已经阅读了一个示例来编写一个示例,但是我如何获得时间来持续更新?

这是我的代码片段:

<body>
<%
java.text.DateFormat df = new java.text.SimpleDateFormat(
"HH:mm:ss:SS z MM/dd/yyyy");
Calendar cal = Calendar.getInstance();
%>

<h1>
Current Date and Time:
<%=df.format(cal.getTime())%>
</h1>
</body>

顺便说一句,我正在使用 tomcat 服务器来部署它

最佳答案

    function updateYourTime() {
var now = new Date(),
months = ['January', 'February', '...'];
time = now.getHours() + ':' + now.getMinutes(),

date = [now.getDate(),
months[now.getMonth()],
now.getFullYear()].join(' ');

document.getElementById('currentTime').innerHTML = [date, time].join(' / ');

setTimeout(updateYourTime, 1000);//This method will call for every second
}
updateYourTime(); // initial call

see here 了解详情

<div id="currentTime"></time>

关于java - JSP - 如何获得以毫秒为单位不断更新的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15539003/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com