确定Twig(或JavaScript)中的国际日期格式,以便在其他地方使用?
在Twig中,可以确定国际日期格式,以JavaScript执行以下操作:确定Twig(或JavaScript)中的国际日期格式,以便在其他地方使用?,javascript,twig,Javascript,Twig,在Twig中,可以确定国际日期格式,以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"); 其
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");
其中某些\u fn在别处定义,但采用日期/时间格式字符串。如何实现“if-usformat?”
或者,这可以通过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");
使用矩量.js怎么样?只需输出细枝值,如下所示:
document.getElementById("dt_tm").value =
some_fn(document.getElementById("inp-dt-tm").value, "{{ frmt }}/YYYY HH:mm");
希望这个帮助函数
somefn
是js函数吗?@Matteo是的。对不起,是的,这就是我在示例中的意思。我已经更新了这个问题。它确实有帮助,但我无法理解的是“usformat”。hi@tyebillion是否要截取浏览器配置?hi@tyebillion是否要截取浏览器配置?是的,我想知道客户端(浏览器)是否为美国日期格式。