⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calc.class.php

📁 一个用PHP编写的
💻 PHP
📖 第 1 页 / 共 4 页
字号:
<?php// The constant telling us what day starts the week. Monday (1) is the// international standard. Redefine this to 0 if you want weeks to// begin on Sunday.if (!defined('DATE_CALC_BEGIN_WEEKDAY')) {    define('DATE_CALC_BEGIN_WEEKDAY', 1);}/** * \ingroup Data * * Date_Calc is a calendar class used to calculate and * manipulate calendar dates and retrieve dates in a calendar * format. It does not rely on 32-bit system date stamps, so * you can display calendars and compare dates that date * pre 1970 and post 2038. * * This source file is subject to version 2.02 of the PHP license, * that is bundled with this package in the file LICENSE, and is * available at through the world-wide-web at * http://www.php.net/license/2_02.txt. * If you did not receive a copy of the PHP license and are unable to * obtain it through the world-wide-web, please send a note to * license@php.net so we can mail you a copy immediately. * * Copyright (c) 1999, 2002, 2003 ispi * * @access public * * @version 1.2.6 * @author Monte Ohrt <monte@ispi.net> */class Date_Calc{    /**     * Returns the current local date. NOTE: This function     * retrieves the local date using strftime(), which may     * or may not be 32-bit safe on your system.     *     * @param string the strftime() format to return the date     *     * @access public     *     * @return string the current date in specified format     */    function dateNow($format='%Y%m%d')    {        return(strftime($format,time()));    } // end func dateNow    /**     * Returns true for valid date, false for invalid date.     *     * @param string year in format CCYY     * @param string month in format MM     * @param string day in format DD     *     * @access public     *     * @return boolean true/false     */    function isValidDate($day, $month, $year)    {        if ($year < 0 || $year > 9999) {            return false;        }      if (!checkdate($month,$day,$year)) {            return false;        }        return true;    }//     /**//     * Returns true for a leap year, else false//     *//     * @param string year in format CCYY//     *//     * @access public//     *//     * @return boolean true/false//     *///    function isLeapYear($year='')    {        if (empty($year)) {            $year = Date_Calc::dateNow('%Y');        }        if (preg_match('/\D/',$year)) {            return false;        }        if ($year < 1000) {            return false;        }        if ($year < 1582) {            // pre Gregorio XIII - 1582            return ($year % 4 == 0);        } else {            // post Gregorio XIII - 1582            return ( (($year % 4 == 0) and ($year % 100 != 0)) or ($year % 400 == 0) );        }    } // end func isLeapYear////    /**//     * Determines if given date is a future date from now.//     *//     * @param string day in format DD//     * @param string month in format MM//     * @param string year in format CCYY//     *//     * @access public//     *//     * @return boolean true/false//     */////    function isFutureDate($day,$month,$year)//    {//        $this_year = Date_Calc::dateNow('%Y');//        $this_month = Date_Calc::dateNow('%m');//        $this_day = Date_Calc::dateNow('%d');////        if ($year > $this_year) {//            return true;//        } elseif ($year == $this_year) {//            if ($month > $this_month) {//                return true;//            } elseif ($month == $this_month) {//                if ($day > $this_day) {//                    return true;//                }//            }//        }////        return false;//    } // end func isFutureDate////    /**//     * Determines if given date is a past date from now.//     *//     * @param string day in format DD//     * @param string month in format MM//     * @param string year in format CCYY//     *//     * @access public//     *//     * @return boolean true/false//     */////    function isPastDate($day,$month,$year)//    {//        $this_year = Date_Calc::dateNow('%Y');//        $this_month = Date_Calc::dateNow('%m');//        $this_day = Date_Calc::dateNow('%d');////        if ($year < $this_year) {//            return true;//        } elseif ($year == $this_year) {//            if ($month < $this_month) {//                return true;//            } elseif ($month == $this_month) {//                if ($day < $this_day) {//                    return true;//                }//            }//        }////        return false;//    } // end func isPastDate//    /**     * Returns day of week for given date, 0=Sunday     *     * @param string day in format DD, default is current local day     * @param string month in format MM, default is current local month     * @param string year in format CCYY, default is current local year     *     * @access public     *     * @return int $weekday_number     */    function dayOfWeek($day='',$month='',$year='')    {        if (empty($year)) {            $year = Date_Calc::dateNow('%Y');        }        if (empty($month)) {            $month = Date_Calc::dateNow('%m');        }        if (empty($day)) {            $day = Date_Calc::dateNow('%d');        }        if ($month > 2) {            $month -= 2;        } else {            $month += 10;            $year--;        }        $day = ( floor((13 * $month - 1) / 5) +            $day + ($year % 100) +            floor(($year % 100) / 4) +            floor(($year / 100) / 4) - 2 *            floor($year / 100) + 77);        $weekday_number = (($day - 7 * floor($day / 7)));        return $weekday_number;    }//    /**//     * Returns week of the year, first Sunday is first day of first week//     *//     * @param string day in format DD, default is current local day//     * @param string month in format MM, default is current local month//     * @param string year in format CCYY, default is current local year//     *//     * @access public//     *//     * @return integer $week_number//     */////    function weekOfYear($day='',$month='',$year='')//    {//        if (empty($year)) {//            $year = Date_Calc::dateNow('%Y');//        }//        if (empty($month)) {//            $month = Date_Calc::dateNow('%m');//        }//        if (empty($day)) {//            $day = Date_Calc::dateNow('%d');//        }//        $iso    = Date_Calc::gregorianToISO($day, $month, $year);//        $parts  = explode('-',$iso);//        $week_number = intval($parts[1]);//        return $week_number;//    } // end func weekOfYear////    /**//     * Returns number of days since 31 December of year before given date.//     *//     * @param string day in format DD, default is current local day//     * @param string month in format MM, default is current local month//     * @param string year in format CCYY, default is current local year//     *//     * @access public//     *//     * @return int $julian//     */////    function julianDate($day='',$month='',$year='')//    {//        if (empty($year)) {//            $year = Date_Calc::dateNow('%Y');//        }//        if (empty($month)) {//            $month = Date_Calc::dateNow('%m');//        }//        if (empty($day)) {//            $day = Date_Calc::dateNow('%d');//        }////        $days = array(0,31,59,90,120,151,181,212,243,273,304,334);////        $julian = ($days[$month - 1] + $day);////        if ($month > 2 && Date_Calc::isLeapYear($year)) {//            $julian++;//        }////        return($julian);//    } // end func julianDate////    /**//     * Returns quarter of the year for given date//     *//     * @param string day in format DD, default is current local day//     * @param string month in format MM, default is current local month//     * @param string year in format CCYY, default is current local year//     *//     * @access public//     *//     * @return int $year_quarter//     */////    function quarterOfYear($day='',$month='',$year='')//    {//        if (empty($year)) {//            $year = Date_Calc::dateNow('%Y');//        }//        if (empty($month)) {//            $month = Date_Calc::dateNow('%m');//        }//        if (empty($day)) {//            $day = Date_Calc::dateNow('%d');//        }////        $year_quarter = (intval(($month - 1) / 3 + 1));////        return $year_quarter;//    } // end func quarterOfYear////    /**//     * Returns date of begin of next month of given date.//     *//     * @param string day in format DD, default is current local day//     * @param string month in format MM, default is current local month//     * @param string year in format CCYY, default is current local year//     * @param string format for returned date//     *//     * @access public//     *//     * @return string date in given format//     */////    function beginOfNextMonth($day='',$month='',$year='',$format='%Y%m%d')//    {//        if (empty($year)) {//            $year = Date_Calc::dateNow('%Y');//        }//        if (empty($month)) {//            $month = Date_Calc::dateNow('%m');//        }//        if (empty($day)) {//            $day = Date_Calc::dateNow('%d');//        }////        if ($month < 12) {//            $month++;//            $day=1;//        } else {//            $year++;//            $month=1;//            $day=1;//        }////        return Date_Calc::dateFormat($day,$month,$year,$format);//    } // end func beginOfNextMonth////    /**//     * Returns date of the last day of next month of given date.//     *//     * @param string day in format DD, default is current local day//     * @param string month in format MM, default is current local month//     * @param string year in format CCYY, default is current local year//     * @param string format for returned date//     *//     * @access public//     *//     * @return string date in given format//     */////    function endOfNextMonth($day='',$month='',$year='',$format='%Y%m%d')//    {//        if (empty($year)) {//            $year = Date_Calc::dateNow('%Y');//        }//        if (empty($month)) {//            $month = Date_Calc::dateNow('%m');//        }//        if (empty($day)) {//            $day = Date_Calc::dateNow('%d');//        }////        if ($month < 12) {//            $month++;//        } else {//            $year++;//            $month=1;//        }////        $day = Date_Calc::daysInMonth($month,$year);////        return Date_Calc::dateFormat($day,$month,$year,$format);//    } // end func endOfNextMonth////    /**//     * Returns date of the first day of previous month of given date.//     *//     * @param string day in format DD, default is current local day//     * @param string month in format MM, default is current local month//     * @param string year in format CCYY, default is current local year//     * @param string format for returned date//     *//     * @access public//     *//     * @return string date in given format//     */////    function beginOfPrevMonth($day='',$month='',$year='',$format='%Y%m%d')//    {//        if (empty($year)) {//            $year = Date_Calc::dateNow('%Y');//        }//        if (empty($month)) {//            $month = Date_Calc::dateNow('%m');//        }//        if (empty($day)) {//            $day = Date_Calc::dateNow('%d');//        }////        if ($month > 1) {//            $month--;//            $day=1;//        } else {//            $year--;//            $month=12;//            $day=1;//        }////        return Date_Calc::dateFormat($day,$month,$year,$format);//    } // end func beginOfPrevMonth////    /**//     * Returns date of the last day of previous month for given date.//     *//     * @param string day in format DD, default is current local day//     * @param string month in format MM, default is current local month//     * @param string year in format CCYY, default is current local year//     * @param string format for returned date//     *//     * @access public//     *//     * @return string date in given format//     *///

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -