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?
source
share