..:D&G:.. Posted March 20, 2016 Share Posted March 20, 2016 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
Mr_Moose Posted March 20, 2016 Share Posted March 20, 2016 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
..:D&G:.. Posted March 20, 2016 Author Share Posted March 20, 2016 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now