php get time

Start and end time of the month


/**
 * 获取上个月开始结束时间
 * @param string $format
 */
function getTime($format = '20190104')
{
    date_default_timezone_set('Asia/Shanghai');
    $i = strtotime($format);
    $Y = date('Y', $i);
    $m = date('m', $i);

    if ($m == 01) {
        $m = 12;
        $Y -= 1;
    }

    $beginThismonth=mktime(0,0,0,$m,1,$Y);
    $endThismonth=mktime(23,59,59,$m,date('t', $i),$Y);

    echo $beginThismonth.' --- '.$endThismonth;
}

getTime();

Guess you like

Origin blog.csdn.net/qq_27084325/article/details/93620744