# Convert seconds to hours

Hello,

I want to convert seconds to hours but I can’t find how.

The problem is thath I am measuring how many hours (each day the sun shines).
But as you know the sun shines in unpredictable patterns.

So setting 3600 seconds to 1 hour won’t work because if the sun only shines for 1500 seconds it won’t count as an hour.

Ive been looking for a solution and tried many different things but I can’t seem to find it.

Do you recall how to do division?
Paul

I don't understand your question. Do you mean that you want hour as a floating point value, e.g. 1500 seconds = 1500/3600 = 0.417 hour ?

how about using a float, 1800 seconds = 0.5 hours, ...

so to get the hours without loosing too much value:
float hours = value / 3600.0f

gives .5 hours for 1800 seconds, 2.0 hours for 7200 seconds

just keep in mind, in statistics raw data is awesome guix:
I don't understand your question. Do you mean that you want hour as a floating point value, e.g. 1500 seconds = 1500/3600 = 0.417 hour ?

Do you want to see your time in this format?

GolamMostafa:
Do you want to see your time in this format?

a bit overkill but useful depending on what you are planning to do in the future might be the time library

So setting 3600 seconds to 1 hour won't work because if the sun only shines for 1500 seconds it won't count as an hour.

You are correct, less than an hour does not count asan hour. I see no problem here!

rico459:
So setting 3600 seconds to 1 hour won't work because if the sun only shines for 1500 seconds it won't count as an hour.

1500 seconds isn't an hour. So why should it count as an hour? Does 1 second count as an hour?

What are you actually trying to achieve?

Steve

rico459:
. . .
The problem is that I am measuring how many hours (each day the sun shines).
But as you know the sun shines in unpredictable patterns.
. . .

I is not quite as unpredictable as you seem to imply. In fact, in pre-historic times, large stone calendars were built which depended on the predictability of the sun's movement (at least, relative to the earth)

int totalSeconds = 4766;
int hr = totalSeconds div 3600;
int min = (totalSeconds - 3600hr) div 60;
int sec = totalSeconds - 3600
hr - 60*min;

jrdoner:
int totalSeconds = 4766;
int hr = totalSeconds div 3600;
int min = (totalSeconds - 3600hr) div 60;
int sec = totalSeconds - 3600
hr - 60*min;

got it thank you!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.