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();
    }
相关推荐
胡译胡说3 小时前
PHP核心开发者Nikita的首次提交,就实现了个寂寞啊
php
老李不敲代码4 小时前
榕壹云预约咨询系统:基于ThinkPHP+MySQL+UniApp打造的灵活预约小程序解决方案
mysql·微信小程序·小程序·uni-app·php
fakaifa5 小时前
【最新版】西陆健身系统源码全开源+uniapp前端
前端·小程序·uni-app·开源·php·约课小程序·健身小程序
万岳软件开发小城8 小时前
基于PHP+Uniapp的互联网医院源码:电子处方功能落地方案
开发语言·uni-app·php·软件开发·互联网医院系统源码·智慧医院app
星云ai9 小时前
矩阵运营的限流问题本质上是平台与创作者之间的流量博弈
服务器·网络·php
会讲英语的码农11 小时前
php基础
开发语言·后端·php
天若有情67319 小时前
用 C++ 模拟 Axios 的 then 方法处理异步网络请求
网络·c++·php
安顾里19 小时前
LInux平均负载
linux·服务器·php
ALe要立志成为web糕手21 小时前
create_function()漏洞利用
安全·web安全·网络安全·php·rce
我最厉害。,。1 天前
-PHP 反序列化&POP 链构造&魔术方法流程&漏洞触发条件&属性修改
开发语言·php