How to format an hour and minute to string?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SebSharper

Hi. I have two ints, one is hour and the other one is minutes.
I need to show this ints in a label, formatting them properly. For example, if the hour or minutes int is less than ten (0-> 9) it should be displayed with the corresponding zeroes (00, 01, 02…)
Is there any way to get this numbers formatted?

:bust_in_silhouette: Reply From: jgodfrey

I think this is what you want:

func _ready():
	var hour = 6
	var minute = 35
	var time = "%02d:%02d" % [hour, minute]
	print(time)  # prints "06:35"

The %02d will zero-pad each value to be 2 digits wide, adding a leading zero if necessary. See the docs here: