php取得指定時間の今月/先月/本年/前年の開始時間と終了時間

10196 ワード

/**
 *              
 * @param $time int
 * @return mixed 11
 */
function currentMonth($time)
{
     
    $info['start'] = strtotime(date( 'Y-m-1 00:00:00', $time ));
    $mdays         = date( 't', $time );
    $info['end']   = strtotime(date( 'Y-m-' . $mdays . ' 23:59:59', $time ));
    return $info;
}

/**
 *               
 * @param $time int
 * @return mixed 11
 */
function lastMonth($time)
{
     
    $datetime      = date('Ymd',$time);
    $info['start'] = strtotime(date("Y-m-1 00:00:00",strtotime("last months",strtotime($datetime))));
    $mdays         = date( 't', $time );
    $info['end']   = strtotime(date( 'Y-m-' . $mdays . ' 23:59:59', $info['start']));
    return $info;
}

/**
 *              
 * @param $time int
 * @return mixed 11
 */
function currentYear($time)
{
     
    $info['start'] = strtotime(date( 'Y-01-01 00:00:00', $time ));
    $info['end']   = strtotime(date( 'Y-12-31 23:59:59', $time ));
    return $info;
}

/**
 *               
 * @param $time int
 * @return mixed 11
 */
function lastYear($time)
{
     
    $info['start'] = strtotime(date( 'Y-01-01 00:00:00', strtotime("-1 years",$time) ));
    $info['end']   = strtotime(date( 'Y-12-31 23:59:59', strtotime("-1 years",$time) ));
    return $info;
}