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);
    }

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值