对于 Python-Sphinx 文档生成器,是否有一种标准方法可以在构建当前渲染时自动填充时间和日期?
如果你只是想在一个页面上的某处显示日期/时间,你可以使用的|today|替代:
Last change: |today|
Run Code Online (Sandbox Code Playgroud)
在我的机器上,结果如下所示:
Last change: 10.07.2019
Run Code Online (Sandbox Code Playgroud)
(德语语言环境,所以日期是德语格式)
要更改日期的格式化方式,您可以today_fmt在配置中使用time.strftime()的格式化指令进行设置。
例如,如果您希望日期/时间看起来类似于 Stack Overflow 上使用的格式,请today_fmt在配置文件中设置如下:
today_fmt = '%b %d %y at %H:%M'
Run Code Online (Sandbox Code Playgroud)
...这会将输出更改为|today|:
Last change: Juli 10 19 at 23:34
Run Code Online (Sandbox Code Playgroud)
注意:根据文档,%b应该是“月份作为语言环境的缩写名称”,所以我希望结果Jul不是Juli. 不知道为什么我的机器上会出现完整的德国月份名称。
您的主题可能不支持它,在这种情况下您必须覆盖适当的模板。
使用Pyramid作为可行的示例:
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
html_last_updated_fmt = '%b %d, %Y'
Run Code Online (Sandbox Code Playgroud)
在你的情况下:
html_last_updated_fmt = '%b %d, %Y, %X'
Run Code Online (Sandbox Code Playgroud)
给你的约会时间调味。
| 归档时间: |
|
| 查看次数: |
1713 次 |
| 最近记录: |