自定义时间函数

<?php

/**

 * @desc获取指定的日期

 * @ string $vdate 2000-01-31

 * @parma int $vnum +~-1

 * @param string $vtype  day/month/year

 * @retuen string date

 */

function datecount($vdate,$vnum,$vtype){

    $day = date('j',strtotime($vdate));

    $month = date('n',strtotime($vdate));

    $year = date('Y',strtotime($vdate));

    switch($vtype){

        case 'day':

           if($vnum >= 0){

                $day = $day + abs($vnum);

            }else{

                $day = $day - abs($vnum);

            }

        break;

        case 'month':

           if($vnum >= 0){

				$month = $month + abs($vnum);

            }else{

                $month = $month - abs($vnum);

            }

        break;

        case 'year':

           if($vnum >= 0){

                $year = $year + abs($vnum);

            }else{

                $year = $year - abs($vnum);

            }

        break;

        default :

            break;

    }

    $time = mktime(0,0,0,$month,$day,$year);

    return date('Y-m-d',$time);

}



echo  datecount('2000-01-31',-1,'month');

  

你可能感兴趣的:(时间函数)