解决 Jekyll 的 post 时区问题

GitHub Pages 托管页面的 post 发表时间可能会出现偏差,这一般是由于时区设置问题。

(要不是凌晨写了几次 blog 我还发现不了这个问题……)之前以为本地编译结果与 GitHub 服务器是完全一致的,后来发现还是 naive。

问题

简单的说,我某篇 Blog 的发表时间写的是 2019-02-18 00:10:07 +08:00,本地编译显示 18 号发表没问题,到了 GitHub Pages 上就显示是 17 号的了。查看网页源码,发现时间被改成了 2019-02-18 00:10:07 +00:00,也就是 UTC 时间了,比北京时间慢了 8 个小时。

解决方案1

_config.yml 中添加 timezone: Asia/Shanghai(北京时间)。具体时区列表可以参考 List of tz database time zones - WikipediaPHP: List of Supported Timezones - Manual

本地编译报错(Windows)

做完上述修改之后 commit 一下,发现 GitHub Page 终于显示正确时间了,但本地编译居然报错:

Jekyll 3.7.3 | Error: No source of timezone data could be found

解决方法2

Gemfile 中添加一行:

1
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]

(64 位 Ruby 使用以上命令;32 位请添加 gem 'tzinfo-data', platforms: [:mingw, :mswin]

然后在网站 Git 目录运行:

1
bundle update

参考链接

-------------本文结束    感谢您的阅读-------------
0%