php计算几天前的方法:首先创建一个PHP示例文件;然后通过“function time_tran($time){...}”方法计算几天前的时间即可。

本文操作环境:Windows7系统、PHP7.1版,DELL G3电脑
PHP计算几分钟前、几小时前、几天前、几个月前、几年前
/*
* $time 需要格式化的时间戳
* return 格式化时间
*/
function time_tran($time){
$text = '';
if(!$time){return $text;}
$current = time();
$t = $current - $time;
$retArr = array('刚刚','秒前','分钟前','小时前','天前','月前','年前');
switch($t){
case $t <p> </p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/skill5233" title="btpanel phpsite 宝塔面板PHP网站"><img
src="https://img.php.cn/upload/skill/000/000/081/179040786932301.jpg" alt="btpanel phpsite 宝塔面板PHP网站" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/skill5233" title="btpanel phpsite 宝塔面板PHP网站" class="overflowclass">btpanel phpsite 宝塔面板PHP网站</a>
<p class="overflowclass">宝塔面板 PHP 网站管理:站点创建、删除、启停、PHP 版本切换、域名管理、SSL证书管理、伪静态管理、数据库管理</p>
</div>
<a rel="nofollow" href="/xiazai/skill5233" title="btpanel phpsite 宝塔面板PHP网站" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div><p>推荐学习:《<a href="https://www.php.cn/course/list/29/type/2.html" target="_blank">PHP视频教程</a>》</p>
php免费学习视频:立即使用
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!










