zoukankan      html  css  js  c++  java
  • 两个日期这间的间隔天数

    /**
         * 两个日期这间的间隔天数
         * @param $date1
         * @param $date2
         * @return float
         */
        public static function daysBetweenDates($date1, $date2)
        {
            $days = floor(abs($date1 - $date2) / 86400);
            return $days;
        }
    
        /**
         * 获取两个时间间隔之间的所有日期
         * @param string|int $minDay like "2015-05-05" or unix_timestamp
         * @param string|int $maxDay like "2015-06-05" or unix_timestamp
         * @return array  ['2015-050-05','2015-05-06',...]
         */
        public static function getAllDays($minDay, $maxDay)
        {
            $minTime = is_numeric($minDay) ? intval($minDay) : strtotime($minDay);
            $maxTime = is_numeric($maxDay) ? intval($maxDay) : strtotime($maxDay);
            $res = [];
            for ($current = $minTime; $current <= $maxTime; $current = strtotime(date("Y-m-d", $current) . " +1 day")) {
                $res[] = date("Y-m-d", $current);
            }
            return $res;
        }
    
        /**
         * 获取两个时间间隔之间的所有星期 (当年的第几周)
         * @param string|int $minDay like "2015-05-05" or unix_timestamp
         * @param string|int $maxDay like "2015-06-05" or unix_timestamp
         * @return array  ['2015 05','2015 06',...]
         */
        public static function getAllWeeks($minDay, $maxDay)
        {
            $minTime = is_numeric($minDay) ? intval($minDay) : strtotime($minDay);
            $maxTime = is_numeric($maxDay) ? intval($maxDay) : strtotime($maxDay);
            $year = date("Y", $minTime);
            $week = intval(date("N", $minTime));
            $startTime = $minTime - ($week - 1) * 86400;
            $startYear = date("Y", $startTime);
            if ($startYear != $year) {
                $startTime = strtotime("{$year}-01-01");
            }
            $endWeek = intval(date("N", $maxTime));
            $endTime = $maxTime + (7 - $endWeek) * 86400;
            $res = [];
            for ($current = $startTime; $current <= $endTime; $current = strtotime(date("Y-m-d", $current) . " +1 week")) {
                $res[] = date("Y W", $current);
            }
            return $res;
        }
    
        /**
         * 获取两个时间间隔之间的所有星期 (第几周)
         * @param string|int $minDay like "2015-05-05" or unix_timestamp
         * @param string|int $maxDay like "2015-06-05" or unix_timestamp
         * @return array  ['2015-05','2015-06',...]
         */
        public static function getAllMonth($minDay, $maxDay)
        {
            $minTime = is_numeric($minDay) ? intval($minDay) : strtotime($minDay);
            $maxTime = is_numeric($maxDay) ? intval($maxDay) : strtotime($maxDay);
            $startTime = strtotime(date("Y-m-01", $minTime));
            $res = [];
            for ($current = $startTime; $current <= $maxTime; $current = strtotime(date("Y-m-d", $current) . " +1 month")) {
                $res[] = date("Y-m", $current);
            }
            return $res;
        }
  • 相关阅读:
    Restful framework【第六篇】认证组件
    Restful framework【第十一篇】url路由控制
    算法学习【第五篇】:排序算法与二分法
    Restful framework【第二篇】APIView
    Restful framework【第三篇】序列化组件
    Restful framework【第四篇】视图组件
    Restful framework【第七篇】权限组件
    Restful framework【第一篇】RESTful 规范
    Restful framework【第九篇】分页器
    转载:“error LNK1169: 找到一个或多个多重定义的符号”的解决方法
  • 原文地址:https://www.cnblogs.com/-mrl/p/7161879.html
Copyright © 2011-2022 走看看