【发布时间】:2020-07-04 00:01:04
【问题描述】:
我想用flask获取当前的UTC时间,所以我写了以下代码:
from flask import Flask
from flask_moment import Moment
from flask import render_template
from datetime import datetime
app = Flask(__name__)
moment = Moment(app)
@app.route('/')
def index():
return render_template('index.html', current_time=datetime.utcnow())
index.html 包含以下代码:
<p>The local date and time is {{ moment(current_time).format('LLL') }}.</p>
<p>That was {{ moment(current_time).fromNow(refresh=True) }}</p>
当我运行应用程序并刷新时,我得到以下结果:
The local date and time is.
That was
有什么问题,我该如何解决?
【问题讨论】:
标签: python flask web-applications momentjs