twigsymfony4

Convert h:m:s to hh:mm:ss in twig


I have a little problem that I can't seem to solve and ask for your help please: I have a branch variable which only contains hour, minute and second with no date. The problem is that its format is h: m: s is I would like to convert it to hh: mm: ss

My variable is : {{hours}} which contains for example: 1:5:7 is i would like to get a result 01:05:07.Can you help me please.

Note that I do not have access to the symfony4 controller because I am a designer thank you in advance.


Solution

  • You can do it using date anyways:

    {% set hours = "1:2:3" %}
    {{ hours|date('H:i:s') }}
    
    #01:02:03