Jump to content

format time


outtaspace
 Share

You are about to reply to a thread that has been inactive for 4364 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I have this code to format my integer into hours, mins, secs.. but i want it to do days, hours, mins, secs..

I cant work out how to change this to include days

integer remaining = 180000;

integer secs = remaining % 60; 
integer mins = ((remaining - secs) % 3600) / 60; 
integer hours = (remaining - mins - secs) / 3600;

 

 

 

 

Link to comment
Share on other sites

EDIT: Altho my first snippet was correct, I prefer Dora's symetrical beauty in her code. I just added what she forgot.

The modulus operator allows you to simplify your calculations a bit.

integer secs = remaining % 60; integer mins = (remaining / 60) % 60;integer hours = ((remaining / 3600) % 3600) % 24;integer days = remaining / 86400;

 2 days, 2 hours if my calculator is correct...

That's all.

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4364 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...