-1

Hello everyone well i have a certain long number and i wish to divide it and show how many minutes and hours remaining :

timeToReceive = Utils.currentTimeMillis() + (60 * 1000 * 60 * 8); // 8 hours

here is my timeToReceive long.

I want to show how much time is remaining for the timeToReceive(it's set for 8 hours in the future).

So i do this :

(timeToReceive - Utils.currentTimeMillis()) / (1000 * 60)

this displays it in minutes, however i want to display it in hours and minutes, how will i go bout doing that?

thanks.

user3569895
  • 13
  • 1
  • 5

2 Answers2

1
timeInMinutes = (timeToReceive - Utils.currentTimeMillis()) / (1000 * 60);

hours = timeInMinutes / 60;
minutes=timeInMinutes % 60;

This works fine

Sunny
  • 308
  • 2
  • 14
0

First count the time in minutes

minutes = (timeToReceive - Utils.currentTimeMillis()) / (1000 * 60)

Then use / operation and % operation

minutes / 60; // will just divide and truncate - gives you hours
minutes % 60; // will give you the rest that is left after dividing - the part that was truncated when you used / operator
Michal Krasny
  • 5,434
  • 7
  • 36
  • 64