Jump to content
Sign in to follow this  
outtaspace

format time

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;

 

 

 

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Try this:

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

Error in hours corrected

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...