Define an international date format in Twig (or JavaScript) for use elsewhere?

In Twig, you can set the international date format to do the following in JavaScript:

var frmt;
{% if usformat %}
    frmt = "MM/DD";
{% else %}
    frmt = "DD/MM";
{% endif %}
document.getElementById("dt_tm").value = 
some_fn(document.getElementById("inp-dt-tm").value, "{{ frmt }}/YYYY HH:mm");

Where some_fn is defined elsewhere but accepts a date / time format string. How to achieve "if usformat?"

Otherwise, can this be achieved in JavaScript?

var frmt;
if (usformat)
    frmt = "MM/DD";
else
    frmt = "DD/MM";
document.getElementById("dt_tm").value = 
some_fn(document.getElementById("inp-dt-tm").value, "{{ frmt }}/YYYY HH:mm");

How about using moment.js?

+4
source share
1 answer

Just enter the tween value as shown below:

document.getElementById("dt_tm").value = 
some_fn(document.getElementById("inp-dt-tm").value, "{{ frmt }}/YYYY HH:mm");

Hope for this help

+2
source

All Articles