/**
* Get the start and end timestamp of the time period
* @param string $timetype time type yesmonth-last month nowmonth-this month yesday-last day nowday-today yesweek-last week nowweek-last week
*/
function getFLtime($timetype){
switch ($timetype){
case 'yesmonth':
//计算上一月
$first = date('Y-m-d H:i:s', mktime(0, 0, 0, date('m') - 1, 1, date('Y')));
$last = date('Y-m-d 23:59:59', strtotime("$first 1 month -1 day"));
break;
case 'nowmonth':
$date = date("Y-m-d");
// 本月第一天
$first = date('Y-m-01 0:0:0', strtotime($date));
// 本月最后一天
$last = date('Y-m-d 23:59:59', strtotime("$first 1 month -1 day"));
break;
case 'yesday':
$first = date('Y-m-d 0:0:0',time()-3600*24);
$last = date('Y-m-d 23:59:59',strtotime($first));
break;
case 'nowday':
$first = date('Y-m-d 0:0:0',time());
$last = date('Y-m-d 23:59:59',strtotime($first));
break;
case 'yesweek':
$timestamp = time();
$first = date('Y-m-d H:i:s', strtotime("last week Monday", $timestamp));
$last = date('Y-m-d H:i:s', (strtotime(date('Y-m-d', strtotime("last week Sunday", $timestamp))) 24 * 3600 - 1));
break;
case 'nowweek':
$timestamp = time();
$first = date('Y-m-d H:i:s', strtotime("this week Monday", $timestamp));
$last = date('Y-m-d H:i:s', (strtotime(date('Y-m-d H:i:s', strtotime("this week Sunday", $timestamp))) 24 * 3600 - 1));
break;
default:
return false;
break;
}
return ['start'=>strtotime($first),'end'=>strtotime($last)];
}
?>
The above is the detailed content of Get the timestamp of each time period, last month, current month, last week, current week, last day, today. For more information, please follow other related articles on the PHP Chinese website!