首页 > 解决方案 > 用树枝比较两个日期

问题描述

我目前正在处理一个活跃的用户概览页面,并且在我被要求提供“最后一个活动列”之前,一切都运行顺利。仅使用日期即可正常运行,但显示的数据应采用“上次活动...分钟前”的形式。现在我面临的问题是我正在运行代码,但我似乎找不到从 currentTime 中减去 lastActivityTime 并将其格式化以显示它的方法。

{% if activeRegularUsers|length > 0 %}
    {% for regularUser in activeRegularUsers %}
    <tbody>
        <tr class="_recolor" id="tableTile">
            <td class="uidCell" id="tableTile">{{ regularUser.uid }}</td>
            <td class="firstNameCell" id="tableTile">{{ regularUser.firstName }}</td>
            <td class="familyNameCell" id="tableTile">{{ regularUser.familyName }}</td>
            <td class="unitCell" id="tableTile">{{ regularUser.readableStateName }}</td>
            <td class="stateCell" id="tableTile">{{ (dateToday - regularUser.LastActivityAt)|date('H:i:s Y-m-d') }}</td>
        </tr>
    </tbody>
    {% endfor %}
{% else %}
    <tbody>
        <td colspan="5" class="_recolor">Keine eingeloggten Benutzer in dieser Benutzergruppe.</td>
    </tbody>
{% endif %}

可以看出在最后的第一下。

我尝试使用 .format('H:i:s Ymd') 以及 |date 格式化 dateToday 和 LastactivityAt ,但似乎没有任何效果。

我会很感激这方面的领导。先感谢您!

标签: phpsymfonytwig

解决方案


推荐阅读