Flask 比较力矩对象jinja2
我试图检查我的时间戳和当前时间是否是同一天,但它不起作用。即使日期匹配,它也总是错误的Flask 比较力矩对象jinja2,flask,jinja2,Flask,Jinja2,我试图检查我的时间戳和当前时间是否是同一天,但它不起作用。即使日期匹配,它也总是错误的 {% if moment().format("MMMM DD, YYYY") == moment(room_params.timestamp).format("MMMM DD, YYYY") %} <span class="time-info">{{ moment().format("HH:mm") }}<
{% if moment().format("MMMM DD, YYYY") == moment(room_params.timestamp).format("MMMM DD, YYYY") %}
<span class="time-info">{{ moment().format("HH:mm") }}</span>
{% endif %}
# Outputs below
moment().format("MMMM DD, YYYY") # September 16, 2020
moment(room_params.timestamp).format("MMMM DD, YYYY") # September 16, 2020
{%if-moment().format(“MMMM-DD,yyyyy”)==moment(房间参数时间戳).format(“MMMM-DD,yyyyy”)%}
{{moment().format(“HH:mm”)}
{%endif%}
#以下产出
矩()格式(“MM DD,YYYY”)#2020年9月16日
时刻(房间参数时间戳)。格式(“MM DD,YYYY”)#2020年9月16日
我还尝试了| string()
过滤器,但也不起作用。
我做错了什么?这是不可能的,因为
矩().format(“HH:mm”)
返回如下HTML span元素:
<span class="flask-moment" data-timestamp="2015-03-26T10:58:51" data-refresh="False"
style="display: none">2015-03-26T10:58:51</span>
然后js:
function checkDate(date) {
var currentDate = moment.utc();
var refDate = moment.utc(date);
var currentDateinDateFormat = currentDate.local().format("MMMM DD, YYYY");
var refDateinDateFormat = refDate.local().format("MMMM DD, YYYY");
var currentDateinYearFormat = currentDate.local().format("YYYY");
var refDateinYearformat = refDate.local().format("YYYY");
if (currentDateinDateFormat == refDateinDateFormat) return refDate.local().format("HH:mm");
if (currentDateinYearFormat == refDateinYearformat) return refDate.local().format("MMM DD");
return refDate.local().format("DD/MM/YYYY");
}
function checkDate(date) {
var currentDate = moment.utc();
var refDate = moment.utc(date);
var currentDateinDateFormat = currentDate.local().format("MMMM DD, YYYY");
var refDateinDateFormat = refDate.local().format("MMMM DD, YYYY");
var currentDateinYearFormat = currentDate.local().format("YYYY");
var refDateinYearformat = refDate.local().format("YYYY");
if (currentDateinDateFormat == refDateinDateFormat) return refDate.local().format("HH:mm");
if (currentDateinYearFormat == refDateinYearformat) return refDate.local().format("MMM DD");
return refDate.local().format("DD/MM/YYYY");
}