generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Turning Seconds Played into Hours, Minutes and Seconds?

Previous Thread :: Next Thread 
MeBilly8440 is not online. MeBilly8440
Joined: 27 Jul 2009
Total Posts: 2783
15 Jul 2013 01:15 PM
This is more of a math question than a scripting question, but I was wondering if there is a math equation that would turn seconds into hours and minutes. This way I could display a player's time-played in a tidy fashion.
Of course, I could always add 1 to minutes every time seconds reached 60 and reset seconds, but I thought I might as well check if there was a math equation for it instead.

Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson
Report Abuse
Zomebody is online. Zomebody
Joined: 01 Jun 2010
Total Posts: 789
15 Jul 2013 01:31 PM
I think these two methods can help you:

math.fmod()
math.modf()

I found them on this page:
http://wiki.roblox.com/index.php/Math.modf#math.fmod

I used these two methods already to make timer in minutes and seconds, so I think it would also be possible for you to use this to make a timer with hours, minutes and seconds.
Report Abuse
MeBilly8440 is not online. MeBilly8440
Joined: 27 Jul 2009
Total Posts: 2783
15 Jul 2013 01:35 PM
The wiki article on that is confusing, and I haven't reached a point in math that I'd learn what those do (I just finished grade 9). Would you not mind providing me an example or two on how I'd use them?

Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
15 Jul 2013 01:37 PM
Think of a second as the base unit.
A minute is made from 60 seconds.
An hour is made from 60 minutes.
A day is made from 24 hours.

If you have the number of seconds, you can easily get the number of minutes, and I want you to think about how that would be done.
Report Abuse
MeBilly8440 is not online. MeBilly8440
Joined: 27 Jul 2009
Total Posts: 2783
15 Jul 2013 01:45 PM
I tried adding a bit of subtraction to the script I came up with yesterday, and I think it might be working... but I'm not sure. Is this correct?

local seconds = math.random(100000)
local days = math.floor(seconds / 86400)
seconds = seconds - (days * 86400)
local hours = math.floor(seconds / 3600)
seconds = seconds - (hours * 3600)
local minutes = math.floor(seconds / 60)
seconds = seconds - (minutes * 60)
print(days.."d,", hours.."h,", minutes.."m,", seconds.."s")

Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
15 Jul 2013 01:55 PM
Yes, that correctly divides a bunch of seconds into days, hours, minutes and seconds.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image