如何在$ smarty.now中添加“N”天?

问题描述 投票:2回答:1

我的页面中有一个名为'priceValidUntil'的参数,对于这个参数,我有一行:

<meta itemprop="priceValidUntil" content="{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}">

我想在15天内添加$smarty.now值,所以我添加了这个:

 <meta itemprop="priceValidUntil" content="{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S' + 15 }">

输出是这样的:

 <meta itemprop="priceValidUntil" content="2024-04-27 23:04:05">

我想要:

<meta itemprop="priceValidUntil" content="2019-05-12 23:04:05">

我怎样才能添加天而不是几年?

php date prestashop smarty prestashop-1.6
1个回答
1
投票

Method 1

根据this link的说法,似乎你可以这样做,也许可以添加:

 {$smarty.now+24*60*60*15|date_format:'%Y-%m-%d %H:%M:%S'}

你的content属性。

  • 在数字中,24表示小时,60表示分钟,其中60表示秒,时间15天,是计算您希望添加到$smarty.now变量的秒数。
  • 然后,您的代码可能如下所示: <meta itemprop="priceValidUntil" content="{$smarty.now+15*24*60*60|date_format:'%Y-%m-%d %H:%M:%S'}">

Method 2

你可能只是试试这个:

{"+15 days"|strtotime|date_format:'%Y-%m-%d %H:%M:%S'}

然后,您的代码可能如下所示:

<meta itemprop="priceValidUntil" content="{$smarty.now+1296000|date_format:'%Y-%m-%d %H:%M:%S'}">
© www.soinside.com 2019 - 2024. All rights reserved.