Convert 1 digit number to HH:mm:ss format in PHP
P粉512729862
P粉512729862 2023-08-06 12:18:43
0
1
463
<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>
P粉512729862
P粉512729862

reply all(1)
P粉969253139

Use sprintf to zero-fill to two digits:

foreach (range(0, 23) as $i) {
   echo sprintf('%02d:00:00' . PHP_EOL, $i);
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!