0

我用这种方法将日期放入 mysql 数据库中2012-08-02 02:20:05。现在,如何使用 smarty 在我的页面中打印。

mycode :(注意:send_date 是行的名称)

$sql = "SELECT m.*, s.photo, s.gender
       FROM mail AS m, signup AS s
       WHERE m.receiver = '" .mysql_real_escape_string($username). "'
       AND m.sender = s.username AND inbox = '1' AND status = '1'
       ORDER BY send_date DESC LIMIT " .$limit;
$rs  = $conn->execute($sql);
4

2 回答 2

2

要将日期从转换2012-08-02 02:20:05为 unix 纪元(自 1970 年以来的秒数),您需要使用strtotime()。要将纪元格式化为您想要使用的任何人类可读的日期date()strtotime()

Smarty knows the date_format modifier. Since Smarty3 this puppy accepts pretty much anything that represents a date (including 2012-08-02 02:20:05). In Smarty2 you might need to convert the string to epoch yourself, something like {$date|strtotime|date_forma:"%d.$m.%Y"}. Note that since Smarty3 date_format accepts format notations from strtotime and date, while Smarty2 only supported the strtotime notation.

于 2012-08-06T08:19:32.090 回答
0

如果您询问如何在 smarty 中输出任何变量,请执行以下操作(假设您的 smarty 设置正确):

在 PHP 中:

/*
assign method: assigns variables to the template
first parameter: The variable name you want to use in your template file
second parameter: the parameter you want to pass to your template file
*/
$smarty->assign('variable', $variable);

在聪明:

/*
brackets {} indicate that smarty is in play
$variable is the variable you passed to smarty
*/

{$variable}

如果这不是您所追求的,请编辑您的问题以使其更清楚。

于 2012-08-04T16:36:01.767 回答