![]() |
Reply From: | timothybrentwood |
Format as you see fit:
func time_to_minutes_secs_mili(time : float):
var mins = int(time) / 60
time -= mins * 60
var secs = int(time)
var mili = int((time - int(time)) * 100)
return str(mins) + ":" + str(secs) + ":" + str(mili)
Thanks for the push in the right direction timothybrentwood, much appreciated.
The final look of the code.
onready var label = $ContDownLabel
onready var gameTimer = $ContDownLabel/GameTimer
func _physics_process(delta):
label.set_text(str(time_to_minutes_secs_mili(gameTimer.get_time_left())))
func time_to_minutes_secs_mili(time : float):
var mins = int(time) / 60
time -= mins * 60
var secs = int(time)
var mili = int((time - int(time)) * 100)
return str(mins) + “:” + str(secs) + “:” + str(mili)
dev_Tfer | 2021-05-13 15:45
For those looking for a time format like this: “00:00:00”, you can replace the last line with:
return str("%0*d" % [2, mins]) + ":" + str("%0*d" % [2, secs]) + ":" + str("%0*d" % [2, mili])
This adds an extra 0 as padding if there’s only a single digit.
BlackDragonBE | 2022-08-15 15:37