Jump to content

[HELP] Converting seconds to minutes : seconds


..:D&G:..

Recommended Posts

Hello guys, is there any way to calculate seconds into minutes and seconds?

I store the player's play time as seconds such as 100 seconds, but I need to make a text gui which says "You have been alive for 12 minutes and 30 seconds"...

So, how should I do this?

Thanks.

Link to comment

You can use the "modulo" operator (%) like this:

local total_time_in_seconds = 119 
local seconds = total_time_in_seconds % 60   -- returns time in seconds: 59 
local minutes = math.floor(total_time_in_seconds/60)   -- returns time in minutes: 1 
local formatted_str = minutes..":"..seconds 

This means: formatted_str = "1:59" as in minutes:seconds

Link to comment
You can use the "modulo" operator (%) like this:
local total_time_in_seconds = 119 
local seconds = total_time_in_seconds % 60   -- returns time in seconds: 59 
local minutes = math.floor(total_time_in_seconds/60)   -- returns time in minutes: 1 
local formatted_str = minutes..":"..seconds 

This means: formatted_str = "1:59" as in minutes:seconds

Thanks a lot!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...