海滨擎蟹

php 获取周日期,月日期数组

/**
 * @param $time
 * @param string $format
 * @return array
 */
function get_week($time, $format = "Y-m-d") {
    $week = date('w', $time);
    $weekname=array('星期一','星期二','星期三','星期四','星期五','星期六','星期日');
    //星期日排到末位
    if(empty($week)){
        $week = 7;
    }
    $data = array();
    for ($i=0; $i<$week; $i++) {
        $data[$i]['date'] = date($format, strtotime('+' . ($i + 1 - $week) . ' days', $time));
        $data[$i]['datetime'] = strtotime($data[$i]['date']);
        $data[$i]['week'] = $weekname[$i];
    }
    return $data;
}

/**
 * @param $time
 * @param string $format
 * @return array
 */
function get_month($time, $format = "Y-m-d") {
    $days = intval(date('d', $time));
    $data = array();
    for ($i=0; $i<$days; $i++) {
        $data[$i]['date'] = date($format, strtotime('+' . ($i + 1 - $days) . ' days', $time));
        $data[$i]['datetime'] = strtotime($data[$i]['date']);
    }
    return $data;
}

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »