Home > Backend Development > PHP Tutorial > php displays various time periods

php displays various time periods

WBOY
Release: 2016-07-30 13:31:09
Original
1286 people have browsed it



First set the time to Beijing time

date_default_timezone_set('PRC');

Current time
$curtime=date("Y-m-d H:i:s", time());

Due to Monday The division is different from what we usually understand, so we need to judge it separately.

if(date('D') == 'Mon'){

Last week:

            $last_week_start=date("Y-m-d H:i:s",strtotime("last Monday"));
                     =date("Y-m-d H:i:s",strtotime("this Monday"));

This week:
          $this_week_start=date("Y-m-d H:i:s",strtotime("this Monday"));
            $this_week_end=date("Y-m-d H:i:s",strtotime("next Monday"));


}else{

Previous week:
          $last_week_start=date("Y-m-d H:i:s" ,strtotime("last Monday -1 week"));
$last_week_end=date("Y-m-d H:i:s",strtotime("this Monday -1 week"));

This week:
$this_week_start=date ("Y-m-d H:i:s",strtotime("this Monday -1 week"));
                $this_week_end=date("Y-m-d H:i:s",strtotime("next Monday"));
}

Last month:
$last_m Month"))."-01 00:00:00";
$last_m Month"))."-01 00:00:00";
This month:
$this_m Month") )."-01 00:00:00";
$this_m Month"))."-01 00:00:00";
Today:
$this_day_start=date("Y-m-d", time())." 00 :00:00";
$this_day_end=date("Y-m-d",strtotime("+1 day"))." 00:00:00";

Copyright statement: This article is an original article by the blogger and has not been authorized by the author. Reprinting is not allowed with the permission of the blogger.

The above introduces the various time periods displayed by PHP, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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