Home > php教程 > php手册 > body text

如何使用PHP获取指定日期所在月的开始日期与结束日期

WBOY
Release: 2016-06-13 11:42:16
Original
976 people have browsed it

复制代码 代码如下:


   /**
     * 获取指定日期所在月的开始日期与结束日期
     * @param string $date
     * @param boolean 为true返回开始日期,否则返回结束日期
     * @return array
     * @access private
     */
    private function getMonthRange( $date, $returnFirstDay = true ) {
        $timestamp = strtotime( $date );
        if ( $returnFirstDay ) {
            $monthFirstDay = date( 'Y-m-1 00:00:00', $timestamp );
            return $monthFirstDay;
        } else {
            $mdays = date( 't', $timestamp );
            $monthLastDay = date( 'Y-m-' . $mdays . ' 23:59:59', $timestamp );
            return $monthLastDay;
        }
    }

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!