phptwigtwig-filter

How can I make a custom time format using TWIG?


How can format time in twig like this: e.g. "13h23" (Hours: 13, minutes: 23) and "13u23" (Hours: 13, minutes: 23)

if I use twig "date" filter, like this: date|date("Hhi") the "h" is converted to 12-hour and I want to include the "h" letter on it. Something similar happens with the other case.


Solution

  • Everyone who read this question and answered or commented didn't actually understand the question. The OP wants to print 'h' or 'u' between the hours and minutes.

    You can do that by using double backslash in front of any character you want to escape. So like so for your example:

    {{ created_date|date('H\\hi') }}
    

    or

    {{ created_date|date('H\\ui') }}
    

    Here is a twigfiddle example: https://twigfiddle.com/ypnau1