问题描述
我是Shopify和.liquid文件语法的新手.
I am new to Shopify and .liquid files syntax.
我目前可以得到两个约会:
I can get two dates currently:
{% assign product_created_date = product.created_at | date: "%a, %b %d, %y" %}
{% assign current_date = 'now' | date: "%a, %b %d, %y" %}
,它提供了我的当前日期以及创建产品的日期.
which gives me the current date and also the date when the product was created.
我想向用户显示主题,即产品发布以来的日期.
I want to show the users in the theme, the date since the product was posted.
我已经阅读了一些液体过滤器,并进行了一些搜索,但是无法确切地找到产品创建后的日子.
I've read some liquid filters and did some search but couldn't find out exactly how I would find the days since product was created.
我们可以使用纯液体语法来计算它吗?
Can we calculate it using purely liquid syntax?
推荐答案
您可以将日期转换为表示自1970-01-01 00:00:00 UTC以来的秒数
You can transform your dates to timestamps representing Number of seconds since 1970-01-01 00:00:00 UTC
{% comment %} convert our dates to Number of seconds
since 1970-01-01 00:00:00 UTC {% endcomment %}
{% assign dateStart = product.created_at | date: '%s' %}
{% assign nowTimestamp = 'now' | date: '%s' %}
{% comment %} difference in seconds {% endcomment %}
{% assign diffSeconds = nowTimestamp | minus: dateStart %}
{% comment %} difference in days {% endcomment %}
{% assign diffDays = diffSeconds | divided_by: 3600 | divided_by: 24 %}
<p>difference in days = {{ diffDays }}</p>
这篇关于Shopify(流动):查找两个日期之间的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!