首页 > 编程 > PHP > 正文

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

2019-11-22 00:18:33
字体:
来源:转载
供稿:网友
复制代码 代码如下:

   /**
     * 获取指定日期所在月的开始日期与结束日期
     * @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;
        }
    }
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表