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();
    }
相关推荐
魔众40 分钟前
ModStartCMS v9.7.0 组件升级优化,模块升级提醒,访问明细导出
php·cms
一人の梅雨4 小时前
京东商品详情深度解析:从接口调用到商业价值挖掘的技术实现
服务器·数据库·php
帅帅梓4 小时前
docker网络
网络·docker·php
吃鱼吃鱼吃不动了6 小时前
什么是负载均衡?
开发语言·php
BingoGo8 小时前
PHP 开发者应该理解的 Linux 入门权限指南
后端·php
苏琢玉9 小时前
再也不用翻一堆日志!一键部署轻量级错误监控系统,帮你统一管理 PHP 报错
go·github·php
JaguarJack10 小时前
PHP 开发者应该理解的 Linux 入门权限指南
后端·php
2301_7931679911 小时前
网络管理部分
linux·运维·服务器·网络·php
李白你好20 小时前
一款基于 PHP 的轻量级Webshell管理工具
php
星光一影1 天前
【OA办公系统】神点企业OA办公助手/全开源
mysql·nginx·开源·php·源代码管理