java中连续减少时间,格式为HH:MM:SS

发布于 2024-10-09 15:35:54 字数 263 浏览 0 评论 0原文

我有一个在项目中实施投标系统的方法,在服务器上的拍卖表中,我有一个用于开始时间和结束时间的字段。

我正在做的是,当用户搜索时,他当然只会看到拍卖仍在进行中的项目。

当用户点击该项目时,他会被购买到可以出价的页面。在那里我得到开始时间和结束时间之间的间隔,然后开始减少时间。

是否有任何现有代码可用于减少

java 中格式为 hh:mm:ss 的

时间?

编辑:问题中有一个错误,结束时间和当前时间之间的时间减少的时间

I have a to implement a bidding system in a project and on the server, in the auction table, i have a field for start time and end time.

What I am doing is that when a user searches, of course he sees only item whose auction is still open

When the user click on the item, he is bought to a page where he can bid. There I get the interval between the start time and the end time and then i start decreasing the time.

is there any existing code that can be used to decrease a time whose format is in

hh:mm:ss in java

??

Edit:there was an error in the questiom, the time to decrease in the time between the end time and the current time

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

━╋う一瞬間旳綻放 2024-10-16 15:35:54

你不需要减少时间。您需要显示还剩多少时间。即现在与结束时间之间的间隔。您使用的是 Java 客户端吗?或者您需要使用 Java 脚本编写代码吗?

编辑:假设出价于 12:00:00 结束,当前时间为 11:59:20(还剩 40 秒),您将计算以下结果。

long endBidTime = .... // today at 12:00:00
long currentTime = System.currentTimeMillis();
long remaining = currentTime - endBidTime;
long hours = remaining / 3600000;
long mins = remaining / 60000 % 60;
long seconds = remaining / 1000 % 60;
String remainingText = "%02d:%02d:%02d".format(hours,mins,seconds);

您始终根据参考时间计算时间,因此随着时间的推移 currentTimeMillis() 自然不需要减少任何内容。

You don't need to decrease the time. You need to show how much time is remaining. i.e. the interval between now and an end time. Are you using a Java client? Or do you need the code to be in Java script?

EDIT: Say the bid ends at 12:00:00 and the current time is 11:59:20 (40 second to go) You would calculate the following.

long endBidTime = .... // today at 12:00:00
long currentTime = System.currentTimeMillis();
long remaining = currentTime - endBidTime;
long hours = remaining / 3600000;
long mins = remaining / 60000 % 60;
long seconds = remaining / 1000 % 60;
String remainingText = "%02d:%02d:%02d".format(hours,mins,seconds);

You are always calculating the time against a reference time so there is no need to decrement any thing as time progresses in currentTimeMillis() naturally.

人│生佛魔见 2024-10-16 15:35:54

我想我将继续使用以下方式,因为我不想依赖客户时间:

->从服务器获取所需的拍卖
->使用服务器时间,计算剩余时间(即当前服务器时间-拍卖结束时间)

->将剩余时间发送给客户端
->在客户端减少直到 0 秒

I think i will proceed using the following way because i don't want to rely on client time:

-> get the required auction from the server
-> using server time, calculate the remaining time (i.e. Current Server Time- auction end time)

-> Send remaining time to client
-> at client decrease until 0 Second

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文