获取指定时间的前一天的日期

WBOY
Release: 2016-06-06 20:36:34
Original
2096 people have browsed it

获取昨天的日期: date('Y-m-d', strtotime('-1 days');

但是如果获取某一天的前一天的日期怎么做呢?

回复内容:

获取昨天的日期: date('Y-m-d', strtotime('-1 days');

但是如果获取某一天的前一天的日期怎么做呢?

<code>$d = new Datetime("2015-03-02 18:00:00");
echo $d->modify("-1 day")->format("Y-m-d H:i:s");
</code>
Copy after login

<code>$date = new DateTime('2015-02-14');
$diff = new DateInterval('P1D');
$date->sub($diff);

echo $date->format('Y-m-d'); // 2015-02-13
</code>
Copy after login

获取的某一天肯定是已知的,直接手动设置成已知时间减去一天的时间就好了吧

<code><?php echo (new DateTime("2014-10-25 -1 days", new DateTimeZone("Asia/Shanghai")))->format("Y/m/d"), "\r\n";

    // or 

    echo date("Y-m-d", strtotime("2014-10-25 -1 days")), "\r\n";
?>
</code>
Copy after login
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