开发者

smarty and date

i get date with: {$smarty.n开发者_JAVA技巧ow|date_format:'%Y-%m-%d %H:%M:%S'}

But how get 20 day after?

If now: 2010 05 05 12:12:12, I wish to show 2010 25 05 12:12:12


{$smarty.now} is a simple timestamp (number of seconds since 1970). So you can just add as many seconds to it as you need:

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

This works in Smarty3, if not in older versions then you might need to do the math with {assign} and/or {math} directives.


Use the strtotime() php function and assign your variable to smarty. Something like this:

<?php
$later = strtotime('+20 day');
$smarty->assign('later', $later);
?>

Then in the template:

{ $later|date_format:'%Y-%m-%d %H:%M:%S'}


You can use strtotime() directly as a modifier.

{"+20 days"|strtotime|date_format:"Y/m/d"}


In newer versions of smarty it will strtotime any string you prepend

I.e. instead of doing {$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'} you can also do {"now"|date_format:'%Y-%m-%d %H:%M:%S'}

To get the date 20 days from now, you can do:

{"+20 days"|date_format:"%Y-%m-%d"}


{assign var="iItemOne" value=$smarty.now}
{assign var="iItemTwo" value=1296000} //60*60*24*15-> for 15 days
{assign var="iSum" value=$iItemOne+$iItemTwo}

{$iSum|date_format:'%Y-%m-%d %H:%M:%S'}


Tested in smarty : Add 1 day ,2 days ......365 days in dynamic date.

$one= date("Y-m-d", strtotime(date("Y-m-d", strtotime('$add dynamic date variable')) . " + 1 day"));
  $this->smarty->assign('one',$one);

$two= date("Y-m-d", strtotime(date("Y-m-d", strtotime('$add dynamic date variable')) . " + 2 day"));
  $this->smarty->assign('two',$two);
...
..

$oneyear= date("Y-m-d", strtotime(date("Y-m-d", strtotime('$add dynamic date variable')) . " + 365 day"));
  $this->smarty->assign('oneyear',$oneyear);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜