Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting data in seconds, want to calculate hours, minutes & seconds

I'm getting a data which contains a certain number.

I need to find how many hours, minutes and seconds it stands for.

for example:

I'm getting the number 248 which means:

00 hours : 04 minutes : 08 seconds

Any ideas would be really apprieciated!

like image 697
Pisti Avatar asked Jan 25 '12 08:01

Pisti


People also ask

How do you convert data into hours?

To convert time to a number of hours, multiply the time by 24, which is the number of hours in a day. To convert time to minutes, multiply the time by 1440, which is the number of minutes in a day (24*60).


1 Answers

Determine hours, minutes and seconds like this:

int hours = (int) (time / 3600);
int minutes = ((int) (time / 60)) % 60;
int seconds = time % 60;

Alternatively, you can determine minutes like this once you know the hours:

int minutes = (int) ((time - hours * 3600) / 60));
like image 194
The Nail Avatar answered Oct 18 '22 21:10

The Nail