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

2018-03-01T17:49:00
/**
 * @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;
}
当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »