+ 1

Getting the remaining time

Hi, I'm trying to get the remaining time in MINUTES (calc) between the current time and this time 23:10. Please check my code. https://code.sololearn.com/cjZ8Y9l65WxH/?ref=app

20th Aug 2019, 7:06 AM
Sibusiso Mbambo
6 odpowiedzi
+ 1
Will this be the values "CURRENT TIME AND DAY IN MINUTES"?
20th Aug 2019, 7:48 AM
Tom Hammerbacher
Tom Hammerbacher - avatar
+ 1
The problem is, that your "minutes" variable is in UNIX-Timestamp format. 'Timestamp.valueOf(today).getTime();' will give you the milliseconds till 01.01.1970.
20th Aug 2019, 7:54 AM
Tom Hammerbacher
Tom Hammerbacher - avatar
+ 1
Tom Hammerbacher CURRENT TIME AND DAY IN MINUTES is the current day and current time converted to milliseconds to minutes.
20th Aug 2019, 7:59 AM
Sibusiso Mbambo
+ 1
Is there any way to get around this? Getting the remaining time between the current time and the future time, example 23:40 in Java.
20th Aug 2019, 8:01 AM
Sibusiso Mbambo
+ 1
Just convert your current timestamp in the same way you convert the 23:10 timestamp. So don't use "getTime()" just use the timestamp in format 'yyyy.mm.dd hh:mm:ss'. Split it by String.split(" ")[1] to get the hh:mm:as part and split that as well to get hours and minutes :)
20th Aug 2019, 8:17 AM
Tom Hammerbacher
Tom Hammerbacher - avatar
0
I've done that in another code where I use the Calendar class. The problem when comparing only time is, for example if the current time is 10:30 and I want a remaining time between 10:30 today and 01:30 the following day, I will get an answer in a negative. So I'm not getting the correct answer.
20th Aug 2019, 8:32 AM
Sibusiso Mbambo