Home > Article > Backend Development > php displays various time periods
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.