根据日期获取当月的开始时间和结束时间

php

浏览数:375

2019-1-8

 /**
     * 根据日期获取本月的开始时间和结束时间
     * @param $date   Y-m    2017-10
     * @return array
     */
    public static function getMonthDaysByDate($date) {
        $data = [];
        $timestamp = strtotime( $date );
        $data['start_time'] = date( 'Y-m-01 00:00:00', $timestamp );
        $mdays = date( 't', $timestamp );
        $data['end_time'] = date( 'Y-m-' . $mdays . ' 23:59:59', $timestamp );
        return $data;
    }