我使用hugo创建了一个帖子
new posts/mypost.md
,它为我创建了mypost.md,并带有这样的标题toml配置
但是,当我在服务器(本地)上运行时,日期时间呈现错误,例如:
我该如何解决这个问题? 预先感谢!
这就是我让它工作的方法:
在
config.toml
添加您的日期格式
[params]
dateFormat = "02 Jan 2006"
您的帖子应在其标题中包含日期:
---
date: "2020-12-23T15:21:54+05:30"
...
---
在布局中使用格式:
<div>{{ .Params.date.Format .Site.Params.dateFormat }}</div>
注意:请勿更改日期格式中的数字。日必须为 02,月份必须为 Jan,年份必须为 2006,等等。
另请检查Hugo 0.87(2021 年 8 月,两年后),其中包含:
请注意,自 Hugo 0.87.0 起,
将返回当前语言的本地化字符串。time.Format
日期/时间格式布局
{{ .Date | time.Format ":date_long" }}
自定义布局的完整列表以及英语示例:
:date_full => Wednesday, June 6, 2018
:date_long => June 6, 2018
:date_medium => Jun 6, 2018
:date_short => 6/6/18
:time_full => 2:09:37 am UTC
:time_long => 2:09:37 am UTC
:time_medium => 2:09:37 am
:time_short => 2:09 am
在配置文件中设置 date_format 对我来说似乎很奇怪。我会在配置文件中设置以下内容:
defaultContentLanguage: nl
languageCode: nl_NL
这些变量不会进入参数,而是在配置文件的根级别。当您拥有这些时,您只需致电:
{{ .Date | time.Format ":date_long" }}
或者...如果您需要其他格式:
{{ .Date | time.Format ":date_medium" }}
日期将以您的语言格式化。
您需要在 config.toml 文件中设置日期格式为 2.1.2006(任何正确的格式,确保 2, Jan, 2006)。
这个链接拯救了我的日子