Convert 1 digit number to HH:mm:ss format in PHP
P粉512729862
2023-08-06 12:18:43
<p>In PHP, how do I convert a 1-digit number to a full time representation, for example: </p>
<pre class="brush:php;toolbar:false;">0
1
2
...
17
18
19</pre>
<p>Convert to a complete time representation, for example: </p>
<pre class="brush:php;toolbar:false;">00:00:00
01:00:00
02:00:00
...
17:00:00
18:00:00
19:00:00</pre>
<p>I tried using the strtotime() and date() functions but didn't really grasp their usage. </p>
Use sprintf to zero-fill to two digits: