我想知道在杰基尔两次约会之间的差别。我怎样才能做到这一点?
{% 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
--- 发布于 2015-07-12 20:35:09
如果你想要做的是知道一个日期是否早于系统时间,那么你可以使用ISO 8601的日期格式,并依赖字典排序。这是一种欺骗,但它适用于你提供的例子。
为了让这个技巧发挥作用,重要的是以ISO8601格式从您的前端获取site.time和日期(下面示例中的page.past_date和page.future_date )。
---
layout: default
past_date: 2015-03-02
future_date: 2016-03-02
---
{% capture currentDate %}{{ site.time | date: '%F' }}{% endcapture %}
{% capture pastDate %}{{ page.past_date | date: '%F' }}{% endcapture %}
{% capture futureDate %}{{ page.future_date | date: '%F' }}{% endcapture %}
<br>currentDate: {{currentDate}}
<br>PastDate earlier than currentDate? {% if pastDate < currentDate %}Yes{% else %}No{% endif %}
<br>FutureDate earlier than currentDate? {% if futureDate < currentDate %}Yes{% else %}No{% endif %}给出以下输出:
currentDate: 2015-07-12 PastDate比currentDate早?是 FutureDate比currentDate早?不是
发布于 2017-03-22 16:16:46
在液体中这样做(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}}小时: 27780 天数: 1157
注意液体的divide_by操作是自动的。
Remainder hours: {{hoursSince | modulo: 24}}剩余小时: 12小时
如果这让你很烦,我也很生气,那么你可以这样做来恢复十进制的名次:
{% assign k = 10 %}
{% assign divisor = 24 %}
{% assign modulus = hoursSince | modulo: 24 | times: k | divided_by: divisor %}
{{daysSince}}.{{modulus}}1157.5
向k添加更多的零以添加更多的小数位。
发布于 2016-01-05 15:40:22
没有人真的回答了这个问题,但这不是不可能的。
您可以得到年份之间的差异,例如自2000年以来已经过去了多少年:
{{ site.time | date: '%Y' | minus:2000 }}至于两次约会之间的几天,那就更难了。最好的选择是查看插件:https://github.com/markets/jekyll-timeago
虽然它的输出可能有点冗长,但是您可以修改插件本身(仔细查看代码,它并不太复杂)
https://stackoverflow.com/questions/31340018
复制相似问题