PHP 日期相关处理,例如:获取本月第一天及最后一天等

//时间相关
    public function timeinfo(){

        //获取今天0点-24点时间戳
        $today = strtotime(date('Y-m-d', time()));
        $todayend = $today + 24 * 60 * 60;


        //获取本周第一天及最后一天
        $weekfirst=strtotime(date('Y-m-d', strtotime('this week')));
        $weeklast=strtotime(date('Y-m-d', strtotime('last day next week')));

        //3.获取当天年份、月份、日及天数.
        echo " 本月共有:".date("t")."天";
        echo " 当前年份".date('Y');
        echo " 当前月份".date('m');
        echo " 当前几号".date('d');

        //1.获取上个月第一天及最后一天.
        echo date('Y-m-01', strtotime('-1 month'));
        echo "<br/>";
        echo date('Y-m-t', strtotime('-1 month'));

        //2016-08-10这天 2个月后的日期
        echo date("Y-m-d",strtotime("+2 month",strtotime("2016-08-10")));

        //获取3 年、月、日 后的日期
        echo date("Y-m-d",strtotime("+3 year",time()));
        echo date("Y-m-d",strtotime("+3 month",time()));
        echo date("Y-m-d",strtotime("+3 day",time()));


    }

    //获取当月第一天和最后一天
    function getthemonth($date)
    {
        $firstday = date('Y-m-01', strtotime(date('Y-m-d')));
        $lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
        return array($firstday,$lastday);
    }

猜你喜欢

转载自blog.csdn.net/csdn_xng/article/details/86686017