我想获得 Jekyll 中两个日期之间的天数差异。我怎样才能做到这一点?
{% capture currentDate %}{{ site.time | date: '%Y-%m-%d' }}{% endcapture %}
{{currentDate}}
{% capture event_date %}{{ entry.date }}{% endcapture %}
{% if event_date < currentDate %}Yes{% else %}No{% endif %}
在条目中有我的 YAML:
---
title: ChartLine C3
type: charts
description: Chart with round for prisma
id: c3-1
date: 2015-07-18
---
最佳答案
在 Liquid(Jekyll 的模板引擎)中执行此操作的方法很愚蠢:
{% 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}}
Hours: 27780
Days: 1157
请注意,Liquid 的
divide_by
操作自动循环。Remainder hours: {{hoursSince | modulo: 24}}
Remainder hours: 12
如果这让你和我一样恼火,那么你可以这样做来恢复小数位:
{% assign k = 10 %}
{% assign divisor = 24 %}
{% assign modulus = hoursSince | modulo: 24 | times: k | divided_by: divisor %}
{{daysSince}}.{{modulus}}
1157.5
向
k
添加更多零添加更多小数位。
关于jekyll - 获取 Jekyll 中两个日期之间的天数差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31340018/