PHP Study Notes of Time strtotime

The beginning is written like this (time interval):

 /**
     * 获取查询条件的日期区间
     * @param $date_flag
     * @return array
     */
    public static function conditionDate($date_flag)
    {
        $time = time();
        $start_date = '';
        $end_date = '';
        //今天
        if ($date_flag === 'today') {
            $start_date = date('Y-m-d', $time);
            $end_date = date('Y-m-d', strtotime($start_date) + 86400);
        }
        //昨天
        if ($date_flag === 'yesterday') {
            $end_date = date('Y-m-d', $time);
            $start_date = date('Y-m-d', strtotime($end_date) - 86400);
        }
        //本周
        if ($date_flag === 'week') {
            $week = date('N');
            $end_date = date('Y-m-d', strtotime(date('Y-m-d', $time)) + 86400);
            $start_date = date('Y-m-d', strtotime($end_date) - 86400 * $week);
        }
        //本月
        if ($date_flag === 'month') {
            $start_date = date('Y-m-01', time());
            $end_date = date('Y-m-d', strtotime(date('Y-m-d', $time)) + 86400);
        }
 
        return ['start'=>$start_date, 'end'=>$end_date];
    }

Are used to count 86400, personalized notes above is the time to start this week, this month, start time, in fact, get there with these simple methods
can refer http://www.caizhichao.cn/738.html, said very detailed.

Guess you like

Origin www.cnblogs.com/zqsb/p/11313730.html