(venv) $ pip install flask-moment
(venv) $ pip install flask-script
from datetime import datetime from flask_script import Manager(切记一定要引入这个flask_script) from flask_moment import Moment moment = Moment(app) manager = Manager(app) @app.route(‘/‘) def index(): return render_template(‘index.html‘,current_time=datetime.utcnow())
{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% block title %}Flasky{% endblock %}
{% block page_content %}
<div class="page-header">
<h1>Hello,world!</h1>
</div>
<p>The local date and time is {{ moment(current_time).format(‘LLL‘) }}.</p>
<p>That was {{ moment(current_time).fromNow(refresh=True) }}.</p>
{% endblock %}
原文:https://www.cnblogs.com/alanlee1473/p/9692798.html