How in php I can convert 1 digit, e.g:
0
1
2
...
17
18
19
To a full time representation like:
00:00:00
01:00:00
02:00:00
...
17:00:00
18:00:00
19:00:00
I tried working with strtotime()
and date()
but didn’t really get the hang out of it
How in php I can convert 1 digit, e.g:
0
1
2
...
17
18
19
To a full time representation like:
00:00:00
01:00:00
02:00:00
...
17:00:00
18:00:00
19:00:00
I tried working with strtotime()
and date()
but didn’t really get the hang out of it
3
Answers
Seems like I was able to fix it myself, for anyone looking for a similar situation. The solution would be:
the output for this is:
15:00:00
You could also use the
mktime()
function, like this:returns:
Sample Output: https://3v4l.org/vuenr
sprintf
with zero padding to two digits:Fiddle here.