Posting Jekyll Content on Time

- 2 mins

Posting of content in Jekyll relies on the date assigned to the post, and the time is relative to the time zone on the server. While this works fine for local installations of Jekyll, it can sometimes be confusing when running Jekyll on the remote servers without being able to control the time zone on that server, like hosting the content on GitHub Pages.

What’s going on?

So, you have written a brand new post. You have run tests on a local Jekyll server and everything looks great. You finally commit the changes to your GitHub site repository, and push the changes to the server. You are excited and full of anticipation to see your new blog post online, you hit refresh in your browser, and… nothing. Another refresh – still nothing.

One of the reasons for this is that you have specified a date/time for your post in the YAML front matter in the header.

By setting date in the front matter you can override the date/time assigned to the post in the format YYYY-MM-DD HH:MM:SS. However, this notation will use the local time zone, set by your operating system. This works fine when running a local installation of Jekyll. However, if your Jekyll installation is running on a remote server (e.g. on the GitHub Pages server) the time on that server is likely not to be the same as the time on your local machine. Jekyll will then wait before processing the contents of the post until the specified time hits the clock on the server.

For your post to be processed according to your time zone, you can either add a UTC offset for your time zone for the post in question, or you can specify a time zone in the Jekyll configuration file.

Setting the date in the front matter

To specify the UTC offset for each post use the following format: YYYY-MM-DD HH:MM:SS +/-TTTT, e.g. 2016-06-12 11:04:00 +0200. This might be useful if you want specify the offset for some specific posts.

title: "Your title"
layout: post
date: 2016-06-12 11:04 +0200
Your content.

Setting the time zone in the Jekyll configuration file

If you want an offset to be applied to all of the dates on your site, you might want to configure Jekyll by setting the time zone for site generation in _config.yml.

Any entry from the IANA Time Zone Database is a valid value, e.g. Europe/Oslo. Wikipedia also has a list of all available values.

# set timezone
timezone: Europe/Oslo

If not specified, Jekyll will use the local time zone, as set by your operating system.

Rustam Mehmandarov

Rustam Mehmandarov

Passionate Computer Scientist

rss facebook twitter github youtube mail spotify instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora