jinja2 how to remove microsecond in datetime

前端 未结 2 1497
逝去的感伤
逝去的感伤 2021-01-22 11:42

In a Jinja2 template I want to display the last login:

Last Login: {{ user.last_seen }}

last_seen is supposed to be a datetime obj

2条回答
  •  梦毁少年i
    2021-01-22 12:04

    Alternatively, a nice solution is flask-moment, where you can use the datetime object and specify how it is to be formatted, like so:

    Last Login: {{ moment(user.last_seen).format('LLLL') }}
    

    which would output like this:

    Last Login: Tuesday, July 29 2014 11:55 AM
    

    You could even use the fromNow() function

    Last Login: {{ moment(user.last_seen).fromNow() }}
    Last Login: 2 days ago
    

提交回复
热议问题