php获取,昨,今,后天.... 本周,月,年...日期时间戳

时间戳->时间转换工具

时间戳(Unix timestamp)转换工具 - 在线工具 (tool.lu)

代码如下:

    public function date()
    {
        /** 日期 **/
        // 今天的日期
        $result['today_date'] = date("Y-m-d");
        // 昨天的日期
        $result['yesterday_date'] = date("Y-m-d", strtotime("-1 day"));
        // 前天的日期
        $result['before_yesterday_date'] = date('Y-m-d', strtotime('-2 days'));
        // 本周的起始日期(周一)
        $result['week_start_date'] = date('Y-m-d', strtotime('monday this week'));
        // 本周的结束日期(周日)
        $result['week_end_date'] = date('Y-m-d', strtotime('sunday this week'));
        // 本月的起始日期
        $result['month_start_date'] = date('Y-m-01');
        // 本月的结束日期
        $result['month_end_date'] = date('Y-m-t');
        // 本年的起始日期
        $result['year_start_date'] = date('Y-01-01');
        // 本年的结束日期
        $result['year_end_date'] = date('Y-12-31');
        // 明天的日期
        $result['tomorrow_date'] = date('Y-m-d', strtotime('+1 day', strtotime(date("Y-m-d"))));
        // 后天的日期
        $result['after_tomorrow_date'] = date('Y-m-d', strtotime('+2 days', strtotime(date("Y-m-d"))));
        // 7 天后的日期
        $result['seven_days_after_date'] = date('Y-m-d', strtotime('+7 days', strtotime(date("Y-m-d"))));
        // 1 个月后的日期
        $result['month_after_date'] = date('Y-m-d', strtotime('+1 month', strtotime(date("Y-m-d"))));
        // 1 年后的日期
        $result['year_after_date'] = date('Y-m-d', strtotime('+1 year', strtotime(date("Y-m-d"))));

        /** 时间戳 **/
        // 今天的时间戳
        $result['today_time'] = strtotime(date("Y-m-d"));
        // 昨天的时间戳
        $result['yesterday_time'] = strtotime("-1 day", strtotime(date("Y-m-d")));
        // 前天的时间戳
        $result['before_yesterday_time'] = strtotime("-2 days", strtotime(date("Y-m-d")));
        // 本周的起始日期(周一)的时间戳
        $result['week_start_time'] = strtotime('monday this week');
        // 本周的结束日期(周日)的时间戳
        $result['week_end_time'] = strtotime('sunday this week');
        // 本月的起始日期的时间戳
        $result['month_start_time'] = strtotime(date('Y-m-01'));
        // 本月的结束日期的时间戳
        $result['month_end_time'] = strtotime(date('Y-m-t'));
        // 本年的起始日期的时间戳
        $result['year_start_time'] = strtotime(date('Y-01-01'));
        // 本年的结束日期的时间戳
        $result['year_end_time'] = strtotime(date('Y-12-31'));
        // 明天的时间戳
        $result['tomorrow_time'] = strtotime('+1 day', strtotime(date("Y-m-d")));
        // 后天的时间戳
        $result['after_tomorrow_time'] = strtotime('+2 days', strtotime(date("Y-m-d")));
        // 7 天后的时间戳
        $result['seven_days_after_time'] = strtotime('+7 days', strtotime(date("Y-m-d")));
        // 1 个月后的时间戳
        $result['month_after_time'] = strtotime('+1 month', strtotime(date("Y-m-d")));
        // 1 年后的时间戳
        $result['year_after_time'] = strtotime('+1 year', strtotime(date("Y-m-d")));

        /** 区间段时间戳 **/
        // 今天的开始时间戳和结束时间戳
        $result['today_start_time'] = strtotime('today');
        $result['today_end_time']   = strtotime('tomorrow') - 1;

        // 昨天的开始时间戳和结束时间戳
        $result['yesterday_start_time'] = strtotime('yesterday');
        $result['yesterday_end_time']   = strtotime('today') - 1;

        // 前天的开始时间戳和结束时间戳
        $result['day_before_yesterday_start_time'] = strtotime('-2 days', strtotime('today'));
        $result['day_before_yesterday_end_time']   = strtotime('yesterday') - 1;

        // 上周的时间戳(从上周一到上周日)
        $result['last_week_start_time'] = strtotime('last week monday');
        $result['last_week_end_time']   = strtotime('last week sunday') + 86399; // 86399 秒是一天的最后一秒

        // 一个月前的时间戳(从一个月前的第一天到最后一天)
        $result['last_month_start_time'] = strtotime('first day of last month midnight');
        $result['last_month_end_time']   = strtotime('last day of last month 23:59:59'); // 最后一天的最后一秒

        // 明天的开始时间戳和结束时间戳
        $result['tomorrow_start_time'] = strtotime('tomorrow');
        $result['tomorrow_end_time']   = strtotime('tomorrow +1 day') - 1;

        // 后天的开始时间戳和结束时间戳
        $result['day_after_tomorrow_start_time'] = strtotime('+2 days midnight');
        $result['day_after_tomorrow_end_time']   = strtotime('+2 days 23:59:59');

        // 本周的开始时间戳和结束时间戳(从本周一到本周日)
        $result['this_week_start_time'] = strtotime('monday this week');
        $result['this_week_end_time']   = strtotime('sunday this week') + 86399;

        // 下周的开始时间戳和结束时间戳(从下周一到下周日)
        $result['next_week_start_time'] = strtotime('monday next week');
        $result['next_week_end_time']   = strtotime('sunday next week') + 86399;

        // 下个月的开始时间戳和结束时间戳(从下个月的第一天到最后一天)
        $result['next_month_start_time'] = strtotime('first day of next month midnight');
        $result['next_month_end_time']   = strtotime('last day of next month 23:59:59');

        dump($result);
        exit();
    }
相关推荐
龙哥·三年风水6 小时前
活动系统开发之采用设计模式与非设计模式的区别-后台功能总结
设计模式·php·tinkphp6
白总Server8 小时前
MySQL在大数据场景应用
大数据·开发语言·数据库·后端·mysql·golang·php
yukai080088 小时前
Python 全栈系列271 微服务踩坑记
python·微服务·php
向宇it10 小时前
一张图解析FastAdmin中的弹出窗口的功能(备份)
php·fastadmin
最美不过下雨天啊11 小时前
php curl发送get、post请求
php
极术社区18 小时前
ResNeXt学习
开发语言·学习·计算机视觉·php
qianer0_019 小时前
php实现kafka
kafka·php·linq
Flying_Fish_roe1 天前
linux-网络管理-网络抓包
linux·网络·php
Dovir多多1 天前
渗透测试入门学习——php文件上传与文件包含
前端·后端·学习·安全·web安全·php
stark张宇1 天前
lnmp - 登录技术方案设计与实现
php·jwt