Home > Backend Development > PHP Problem > How to convert timestamp in php to days

How to convert timestamp in php to days

藏色散人
Release: 2023-03-09 21:38:01
Original
2194 people have browsed it

How to convert php timestamp to days: First create a PHP sample file; then convert the timestamp to days through "(time()-$v['createtime'])/86400;" .

How to convert timestamp in php to days

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

php timestamp is converted into days and rounded to an integer

public function edit()
{
global $_W;
global $_GPC;
$openid=$_W['openid'];
$boards = pdo_fetchall('select b.id,b.logo,b.title,f.createtime from ' . tablename('ewei_shop_sns_board_follow') . ' f ' . ' left join ' . tablename('ewei_shop_sns_board') . ' b on f.bid = b.id ' . ' where f.uniacid=:uniacid and f.openid=:openid ', array(':uniacid' => $_W['uniacid'], ':openid' => $openid));
$boards = set_medias($boards, 'logo');
include $this->template();
}
 
 
//html 代码  
<div class="mtvc mm">
{loop $boards $k $v}
<div>
<img class="mui-media-object mui-pull-left" src="{$v[&#39;logo&#39;]}">
<div class="mui-media-body">
{$v[&#39;title&#39;]}
<p class=&#39;mui-ellipsis&#39;>已坚持<span>
<?php
$times= (time()-$v[&#39;createtime&#39;])/86400;
// echo $times."<br>";
if( $times<1){
echo "1";
}else{
echo round("$times");
}
?>
</span>天</p>
<img class="mui-media-object mui-pull-right imgdel" src="../addons/ewei_shopv2/plugin/sns/static/images/btndel.png" onClick="delItem(this, id)"/></br>
</div>
</div>
{/loop}
</div>
Copy after login

Key points

{$v[&#39;title&#39;]} =<?php  echo $v[&#39;title&#39;];  ?>
Copy after login

The round() function rounds floating point numbers.

Example

<?php
echo(round(0.60));
echo(round(0.50));
echo(round(0.49));
echo(round(-4.40));
echo(round(-4.60));
?>
Copy after login

Output:

1
1
0
-4
-5
Copy after login

[Recommended learning: PHP video tutorial]

The above is the detailed content of How to convert timestamp in php to days. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template