Jonibus
|
  |
| Joined: 30 Jan 2010 |
| Total Posts: 8985 |
|
|
| 20 Jun 2014 12:47 PM |
What would be a nice way to convert minutes into hours and minutes?
Follow me on twitter: @Jonibus_RBX |
|
|
| Report Abuse |
|
|
Locard
|
  |
| Joined: 13 Apr 2014 |
| Total Posts: 3516 |
|
|
| 20 Jun 2014 12:48 PM |
local number = 182 local hours = math.floor(number/60) local minutes = number-(60*hours) |
|
|
| Report Abuse |
|
|
Phyclops
|
  |
| Joined: 27 Sep 2012 |
| Total Posts: 5895 |
|
|
| 20 Jun 2014 12:49 PM |
use something like if minutes.Value==>60 then
and make a value which is # hours # mins and set the value to whatever it is above 60 as the mins and hours 1 etc |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 12:51 PM |
local time = tick() local hours = math.floor(time/3600)%24 local minutes = math.floor(time/60)%60 local seconds = math.floor(time)%60 print(hours .. ":" .. minutes) |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 12:54 PM |
Actually, use this as the print line:
print(('%02i:%02i:%02i'):format(hours, minutes, seconds)) |
|
|
| Report Abuse |
|
|
jakej78b
|
  |
| Joined: 09 Mar 2011 |
| Total Posts: 813 |
|
|
| 20 Jun 2014 12:55 PM |
| Too lazy to pull out the ole' calculator? |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 12:55 PM |
function ConvertMinutesToHoursAndMinutes(minutes) local hours = 0 local new_minutes = 0 hours = math.floor(minutes/60) new_minutes = minutes-(hours*60) local new_time = hours.." hours and "..new_minutes.." minutes" return new_time end
local timeytime = ConvertMinutesToHoursAndMinutes(160) print(timeytime)
>2 hours and 40 minutes |
|
|
| Report Abuse |
|
|
| |
|
Phyclops
|
  |
| Joined: 27 Sep 2012 |
| Total Posts: 5895 |
|
|
| 20 Jun 2014 12:57 PM |
@jak @meow
are you guys stupid? he wants a script i'm pretty sure he knows how to divide by 60 |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 12:58 PM |
Oh, MINUTES into HOURS and MINUTES.
Ok,
local time = 105 --Minutes
local hours = (time/60)%60 local minutes = (time)%60
print(('%02i:%02i or %i Hours %i Minutes'):format(hours, minutes, hours, minutes)) |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 12:58 PM |
| Lol he said he's bad at math :P so I would guess not. (No offense) |
|
|
| Report Abuse |
|
|
Jonibus
|
  |
| Joined: 30 Jan 2010 |
| Total Posts: 8985 |
|
|
| 20 Jun 2014 12:58 PM |
They probably are, they assumed I'm doing math homework or something, rather than looking for an algorithm
Follow me on twitter: @Jonibus_RBX |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 01:00 PM |
| So, yeah. Use modulo, where you make a division and get the remainder. You can math.floor it, if you don't want a decimal, but if you are using it in a string you can just use string.format with %i (Integers) or %02i (Integers with a minimum of two "0"s, IE: 5 -> 05, 20 -> 20, 0 -> 00) |
|
|
| Report Abuse |
|
|
Locard
|
  |
| Joined: 13 Apr 2014 |
| Total Posts: 3516 |
|
|
| 20 Jun 2014 01:01 PM |
Notunknown,
I applaud your technique. |
|
|
| Report Abuse |
|
|
jakej78b
|
  |
| Joined: 09 Mar 2011 |
| Total Posts: 813 |
|
|
| 20 Jun 2014 01:02 PM |
| He's capable of the script, he just needs the math part which about 5 people have provided him with so I'm sure he'll be fine. Sorry, I am pretty stupid btw @ FlamingTrollAbout |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 01:03 PM |
Oh, and if the time in minutes can have decimals:
local time = 105.25
local hours = (time/60)%60 local minutes = (time)%60 local seconds = (time*60)%60 --Multiply by 60 to get the number of seconds
print(('%02i:%02i:%02i or %i Hours %i Minutes %i Seconds'):format(hours, minutes, seconds, hours, minutes, seconds)) |
|
|
| Report Abuse |
|
|
Jonibus
|
  |
| Joined: 30 Jan 2010 |
| Total Posts: 8985 |
|
|
| 20 Jun 2014 01:07 PM |
Yeah, @jake I used Locard's method, because it made sense towards what I'm doing (a string containing hours and minutes in the sentence)
Notunknowns methods are great for clocks and timers, I'll take note of that for the future.
Follow me on twitter: @Jonibus_RBX |
|
|
| Report Abuse |
|
|
jakej78b
|
  |
| Joined: 09 Mar 2011 |
| Total Posts: 813 |
|
|
| 20 Jun 2014 01:10 PM |
| Big fan of your zones too, I don't know why it hasn't replaced dart's yet. :v |
|
|
| Report Abuse |
|
|