flask-moment

提供了非常灵活、丰富的时间日期格式化方法。在模板中,
可以通过对moment类调用format方法来格式化时间和日期,
moment的构造方法接收使用utcnow方法创建的datetime对象作为参数,
即message对象的timestamp属性。format方法接收特定的格式字符串来渲染时间格式。
时间日期会在页面加载完成后执行js函数使用moment。js渲染。所以时间日期的显示会有微小的延迟


内置格式化字符串
格式化字符串                输出示例
L        2017-07-26
LL        2017年7月26日
LLL   2017年7月26日早上8点00分
LLLL  2017年7月26日星期三早上8点00分
LT    早上8点00分
LTS    早上8点0分0秒
111    2017年7月26日  02:23
1111    2017年7月26日星期四  02:32
<small data-toggle="tooltip" data-placement="top"
       data-timestamp="{{ message.timestamp.strftime('%Y-%m-%dT%H:%M:%SZ') }}"
       data-delay="500">
    {{ moment(message.timestamp).fromNow(refresh=True) }}
</small>

 

 

 自定义显示函数

$(function () {
    function render_time() {
        return moment($(this).data('timestamp')).format('llll')
    }
    $('[data-toggle="tooltip"]').tooltip(
        {title: render_time}
    );
});
posted @ 2019-12-30 18:08  慕沁  阅读(177)  评论(0)    收藏  举报