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();
    }
相关推荐
哥坐11路13 小时前
网络IP跳动问题解决详
开发语言·php
一只哒布刘19 小时前
第六次作业
开发语言·php
寰宇软件20 小时前
PHP房屋出租出售高效预约系统小程序源码
前端·小程序·uni-app·vue·php
HUNAG-DA-PAO20 小时前
Redis存在线程安全吗?为什么?
redis·安全·php
ianozo21 小时前
BUU40 [安洵杯 2019]easy_serialize_php
android·开发语言·php
zgscwxd1 天前
php session数据存储位置选择
开发语言·php
ianozo2 天前
CTF 代码学习日记 PHP
java·学习·php
ontheway-xx2 天前
PHP+Apache+MySQL安装(Windows)
开发语言·php
网络安全queen2 天前
公证 网络安全
开发语言·php
慢一点会很快2 天前
FRRouting配置与OSPF介绍,配置,命令,bfd算法:
算法·智能路由器·php·ospf