.Date .Lastmod return + in place of +


I have been working on some things related to .Date and .Lastmod.

I noticed that in the them I am using ‘ananke’ that there is a html tag


The site code is as follows:

<time class="f6 mv4 dib tracked" datetime="{{ $thisDate.Format "2006-01-02T15:04:05Z07:00" }}>

This generate code:

<time class="f6 mv4 dib tracked" datetime="2020-07-16T00:00:00&#43;09:00">

I believe this is not expected input for the



I have tried using safeHTML and safeHTMLAttr but the result is the same. I think this is because .Date and .Lastmod return the ascii code by default.

Has anyone seen this? Is a real issue or not? I ask because the spec clearly calls for and + symbol and not the ascii code representation.


First, your time format string should be 2006-01-02T15:04:05-07:00 not 2006-01-02T15:04:05Z07:00. The Z is shorthand for +00:00; it is not a separator like T.

Second, you need to use safeHTML like this:

{{ printf `<time datetime="%s">` (.Date.Format `2006-01-02T15:04:05-07:00`) | safeHTML }}{{ .Date.Format "January 2, 2006" }}</time>
1 Like

The general rule with the Go HTML template engine is to print either the entire tag or the entire attribute, not just a value.

The attribute version to go along with @jmooring’s example:

<time class="f6 mv4 dib tracked" {{ printf `datetime="%s"` ($thisDate.Format "2006-01-02T15:04:05T07:00") | safeHTMLAttr }}> 
1 Like

This pretty close. The final T needs to be a +. Though it seems the 07:00 is not being updated from the actual .Date object. Rather is being maintained from the format.

I am wondering why the 07:00 is maintained even though the front matter date ends with a +09:00. This works in my case since my timezone is +09:00. But would break for anyone who is outside of my timezone and would require manual fixing.

So thanks for this however. Its good to know.

The oringal code basically comes from the ananke theme. I will see if I can submit a pull request at some point to have theme updated.

No, it does not. That is why “the 07:00 is not being updated from the actual .Date object.”

The date format should be 2006-01-02T15:04:05-07:00.

So I just went through documenting my testing for like one and half pages, only to discover the solution. Yay for for documenting how to reproduce.

The correct solution, which makes sense. use a Z before the timezone offset.

Complete example:

      <time class="f6 mv4 dib tracked" {{ printf `datetime="%s"` (.Date.Format "2006-01-02T15:04:05Z07:00") | safeHTMLAttr }}>

which produces:

<time class="f6 mv4 dib tracked" datetime="2020-05-16T12:00:00+09:00">

from a front matter data of:

date:   2020-05-16T12:00:00+0900

I will see if I can get this added to the ananke theme.

Thanks for the help guys.

Using a Z before the offset will eliminate the offset if the date’s offset is zero.

date1: 2020-07-18T09:15:13-04:00
date2: 2020-07-18T09:15:17+04:00
date3: 2020-07-18T09:15:17-00:00
date4: 2020-07-18T09:15:17+00:00

Format: 2006-01-02T15:04:05Z07:00


Format: 2006-01-02T15:04:05-07:00


Either way produces a technically correct result, but they are not interchangeable.


Hmmm. Thats interesting. So in your final example you do not appear to use Z but rather just the - sign.

A dateitme ending with Z is valid. So this would not be too much of an issue. At least it appears it would not be too much of an issue.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.