hugo/docs/content/en/functions/unix.md
2021-10-31 13:53:55 +01:00

1.1 KiB

title draft description date publishdate lastmod keywords categories menu signature workson hugoversion relatedfuncs deprecated aliases
.Unix false .Unix returns the local Time corresponding to the given Unix time, sec seconds and nsec nanoseconds since January 1, 1970 UTC. 2017-02-01 2017-02-01 2017-02-01
dates
time
functions
docs
parent
functions
.Unix
times
Format
dateFormat
now
time
false

Example: Time Passed Since Last Modification

This very simple one-liner uses now.Unix to calculate the amount of time that has passed between the .LastMod for the current page and the last build of the current page.

{{< code file="time-passed.html" >}} {{ div (sub now.Unix .Lastmod.Unix) 86400 }} {{< /code >}}

Since both values are integers, they can be subtracted and then divided by the number of seconds in a day (i.e., 60 * 60 * 24 == 86400).

{{% note %}} Hugo's output is static. For the example above to be realistic, the site needs to be built every day. {{% /note %}}