I’ll create a count timer for my android app. I want to calculate how much time have in 24:00 in hours from current time. I couldn’t not find any solutions and it’s so complicated for me to calculate it with miliseconds.
For Example:
Now time is: 22.55
Have 1 hours and 5 minutes to 00.00
I’ll make count timer with this like:
Remaining: 1 hours 5 Minutes
Anyone can help me?
Thanks a lot.
2
Answers
You can use
java.time.Duration
to compute the time difference between now and midnight:Days are not always 24 hours long
On some dates in some time zones, the day is not 24 hours long. Some days may run 23, 23.5, 25, or some other number of hours long.
So let java.time determine the first moment of the following day.
See this code run live at IdeOne.com.