计算杰基尔的天数 [英] Count days in Jekyll
本文介绍了计算杰基尔的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Jekyll网站,我想创建一个日计数器,从1开始,然后每天将+1添加到计数器中.
I have a a Jekyll website and I would like to create a day counter, starting from 1 and then every day it should add +1 to the counter.
所以今天它会说:
第1天
明天应该说
第2天
第二天:
第3天
有可能在jekyll做吗?
is that possible to do in jekyll?
推荐答案
您只需要计算两个日期之间的差额即可.这里有一些关于此的讨论: https://stackoverflow.com/a/34615552/1645925
You just need to calculate the difference between two dates. There is some discussion about that here: https://stackoverflow.com/a/34615552/1645925
我最喜欢的答案是:
{% assign today = site.time | date: '%s' %}
{% assign start = '20-01-2014 04:00:00' | date: '%s' %}
{% assign secondsSince = today | minus: start %}
{% assign hoursSince = secondsSince | divided_by: 60 | divided_by: 60 %}
{% assign daysSince = hoursSince | divided_by: 24 %}
Hours: {{hoursSince}}
Days: {{daysSince}}
我相信site.time
是指托管您网站的服务器时间,但是您可以使用'now'
来使用用户时间.
I believe site.time
refers to the server time that your site is hosted on but you can use 'now'
to use the users time.
这篇关于计算杰基尔的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文