Home  >  Article  >  Backend Development  >  分享一段php获取任意时间的前一天代码

分享一段php获取任意时间的前一天代码

WBOY
WBOYOriginal
2016-06-23 13:33:24839browse

<?php /** * 获取给定日期的前一天 * @param string $date * @return string $yesterday */function getYesterday($date){    if(empty($date))    {        $yesterday = date("Y-m-d",strtotime("-1 day"));    }else{        $arr = explode('-', $date);        $year = $arr[0];        $month = $arr[1];        $day = $arr[2];        $unixtime = mktime(0,0,0,$month,$day,$year)-86400;        $yesterday = date('Y-m-d',$unixtime);    }    return $yesterday;}

Statement:
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