php日期时间函数,php里获取前一天的时间?

用户投稿 16 0

关于“php_日期区间”的问题,小编就整理了【2】个相关介绍“php_日期区间”的解答:

php里获取前一天的时间?

//获得当前时间

//date()格式化时间返回String类型。 date("Y-m-d H:i:s")

$current_date = date(’Y-m-d’,time());

//根据当前时间加一周后

$weekLater = date(’Y-m-d’,strtotime("$current_date + 1 week"));

echo $weekLate;

// 2009-05-26 加一天的日期

$tomorrow = date(’Y-m-d’,strtotime("2009-05-26 + 1 day"));

echo $tomorrow; // 2009-05-27

也可以这样 date("Y-m-d",strtotime("-1 day")) ;直接获得前一天时间

php中,计算指定日期还有多少天?

思路是先求两个时间的秒数差,然后将结果转换即可:

echo calcTime('2018-08-20', '2018-08-30');function calcTime($fromTime, $toTime){ //转时间戳 $fromTime = strtotime($fromTime); $toTime = strtotime($toTime); //计算时间差 $newTime = $toTime - $fromTime; return round($newTime / 86400) . '天' . round($newTime % 86400 / 3600) . '小时' . round($newTime % 86400 % 3600 / 60) . '分钟'; }

到此,以上就是小编对于“php_日期区间”的问题就介绍到这了,希望介绍关于“php_日期区间”的【2】点解答对大家有用。

抱歉,评论功能暂时关闭!