Continuous time reduction in java in the format HH: MM: SS

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

What I do is that when the user searches, of course, he sees only the item whose auction is still open

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

is there any existing code that can be used to reduce the time, the format of which is in

hh: mm: ss in java

??

Edit: There was an error in the quest, time to reduce the time between the end time and the current time

+4
source share
2 answers

You do not need to reduce time. You need to show how much time is left. those. interval between time and end time. Are you using a Java client? Or do you need code for a Java script?

EDIT: declare that the auction ends at 12:00:00 and the current time is 11:59:20 (40 seconds to go). You have calculated 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 always calculate time compared to control time, so there is no need to reduce any thing as time develops in currentTimeMillis () naturally.

+3
source

I think that I will continue to use the following method because I do not want to rely on client time:

-> get the required auction from the server -> using the server time, calculate the remaining time (i.e. the end time of the current auction time server)

-> Sending the remaining time to the client -> when reducing the client to 0 seconds

+1
source

Source: https://habr.com/ru/post/1333841/


All Articles