Php 秒到分钟:从mysql到smarty的秒数
我有这个疑问Php 秒到分钟:从mysql到smarty的秒数,php,mysql,smarty,Php,Mysql,Smarty,我有这个疑问 $result = select_query("tblemails", "", array("userid" => $userid), "id", "DESC", "0,5"); $lastfivemail = array(); while ($data = mysql_fetch_array($result)) { $lastfivemail[] = array("id" => $data["id"], "processtime" => $data["proce
$result = select_query("tblemails", "", array("userid" => $userid), "id", "DESC", "0,5");
$lastfivemail = array();
while ($data = mysql_fetch_array($result))
{
$lastfivemail[] = array("id" => $data["id"], "processtime" => $data["processtime"], "date" => frommysqldate($data["date"], "time"), "subject" => $data["subject"] ? $data["subject"] : "No Subject");
continue;
}
$templatevars["lastfivemail"] = $lastfivemail;
还有这个
"processtime" => $data["processtime"]
以秒为单位显示发送电子邮件所需的时间
我需要在一分钟内显示它:第二种格式
这是聪明的一面
<div class="clientssummarybox">
<div class="title">{$_ADMINLANG.clientsummary.emailsheading}</div>
<table class="clientssummarystats" cellspacing="0" cellpadding="2">
{foreach key=num from=$lastfivemail item=email}
<tr class="{cycle values=",altrow"}"><td align="center">{$email.date} - <a href="#" onClick="window.open('clientsemails.php?&displaymessage=true&id={$email.id}','','width=650,height=400,scrollbars=yes');return false">{$email.subject}</a></td><td>{$email.processtime}</td></tr>
{foreachelse}
<tr><td align="center">{$_ADMINLANG.clientsummary.noemails}</td></tr>
{/foreach}
</table>
</div>
</td><td width="25%" valign="top">
{$\u ADMINLANG.clientsummary.EmailSheding}
{foreach key=num from=$lastfivemail item=email}
{$email.date}-{$email.processtime}
{foreachelse}
{$\u ADMINLANG.clientsummary.noemails}
{/foreach}
谢谢不是最优雅的,但是:
$t = $data["processtime"];
$mins = floor($t/60);
$secs = $t%60;
$data["processtime"] = sprintf("%02d:%02d",$mins,$secs);
使用Smarty 2和更高版本,您可以使用
{$email.processtime | date_格式:'%H:%M:%S'}
我最近使用了一个“仅smarty”解决方案来解决将秒转换为更可读的H:M:S格式的问题。假设您有一个变量$seconds
{assign var='duration' value='%02d:%02d:%02d'}
Duration: {$seconds|sprintf:floor($seconds/3600):(($seconds/60)%60):$seconds}
在php中通过date()函数执行此操作,只需使用指定的变量即可。