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

📄 date.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 5 页
字号:
            // additional formats            case Zend_Date::ERA :                $year = $this->date('Y', $this->getUnixTimestamp(), false);                if ($year < 0) {                    return Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Abbr', '0'));                }                return Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Abbr', '1'));                break;            case Zend_Date::ERA_NAME :                $year = $this->date('Y', $this->getUnixTimestamp(), false);                if ($year < 0) {                    return Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Names', '0'));                }                return Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Names', '1'));                break;            case Zend_Date::DATES :                return $this->toString(Zend_Locale_Format::getDateFormat($locale), 'iso', $locale);                break;            case Zend_Date::DATE_FULL :                $date = Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'full'));                return $this->toString($date, 'iso', $locale);                break;            case Zend_Date::DATE_LONG :                $date = Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'long'));                return $this->toString($date, 'iso', $locale);                break;            case Zend_Date::DATE_MEDIUM :                $date = Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'medium'));                return $this->toString($date, 'iso', $locale);                break;            case Zend_Date::DATE_SHORT :                $date = Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'short'));                return $this->toString($date, 'iso', $locale);                break;            case Zend_Date::TIMES :                return $this->toString(Zend_Locale_Format::getTimeFormat($locale), 'iso', $locale);                break;            case Zend_Date::TIME_FULL :                $time = Zend_Locale_Data::getContent($locale, 'time', 'full');                return $this->toString($time, 'iso', $locale);                break;            case Zend_Date::TIME_LONG :                $time = Zend_Locale_Data::getContent($locale, 'time', 'long');                return $this->toString($time, 'iso', $locale);                break;            case Zend_Date::TIME_MEDIUM :                $time = Zend_Locale_Data::getContent($locale, 'time', 'medium');                return $this->toString($time, 'iso', $locale);                break;            case Zend_Date::TIME_SHORT :                $time = Zend_Locale_Data::getContent($locale, 'time', 'short');                return $this->toString($time, 'iso', $locale);                break;            case Zend_Date::ATOM :                return $this->date('Y\-m\-d\TH\:i\:sP', $this->getUnixTimestamp(), false);                break;            case Zend_Date::COOKIE :                return $this->date('l\, d\-M\-y H\:i\:s e', $this->getUnixTimestamp(), false);                break;            case Zend_Date::RFC_822 :                return $this->date('D\, d M y H\:i\:s O', $this->getUnixTimestamp(), false);                break;            case Zend_Date::RFC_850 :                return $this->date('l\, d\-M\-y H\:i\:s e', $this->getUnixTimestamp(), false);                break;            case Zend_Date::RFC_1036 :                return $this->date('D\, d M y H\:i\:s O', $this->getUnixTimestamp(), false);                break;            case Zend_Date::RFC_1123 :                return $this->date('D\, d M Y H\:i\:s O', $this->getUnixTimestamp(), false);                break;            case Zend_Date::RFC_3339 :                return $this->date('Y\-m\-d\TH\:i\:sP', $this->getUnixTimestamp(), false);                break;            case Zend_Date::RSS :                return $this->date('D\, d M Y H\:i\:s O', $this->getUnixTimestamp(), false);                break;            case Zend_Date::W3C :                return $this->date('Y\-m\-d\TH\:i\:sP', $this->getUnixTimestamp(), false);                break;        }    }    /**     * Return digit from standard names (english)     * Faster implementation than locale aware searching     *     * @param  string  $name     * @return integer  Number of this month     * @throws Zend_Date_Exception     */    private function getDigitFromName($name)    {        switch($name) {            case "Jan":                return 1;            case "Feb":                return 2;            case "Mar":                return 3;            case "Apr":                return 4;            case "May":                return 5;            case "Jun":                return 6;            case "Jul":                return 7;            case "Aug":                return 8;            case "Sep":                return 9;            case "Oct":                return 10;            case "Nov":                return 11;            case "Dec":                return 12;            default:                require_once 'Zend/Date/Exception.php';                throw new Zend_Date_Exception('Month ($name) is not a known month');        }    }    /**     * Counts the exact year number     * < 70 - 2000 added, >70 < 100 - 1900, others just returned     *     * @param  integer  $value year number     * @return integer  Number of year     */    private static function _century($value)    {        if ($value >= 0) {            if ($value < 70) {                $value += 2000;            } else if ($value < 100) {                $value += 1900;            }        }        return $value;    }    /**     * Sets the given date as new date or a given datepart as new datepart returning the new datepart     * This could be for example a localized dayname, the date without time,     * the month or only the seconds. There are about 50 different supported date parts.     * For a complete list of supported datepart values look into the docu     *     * @param  string|integer|array|Zend_Date  $date    Date or datepart to set     * @param  string                          $part    OPTIONAL Part of the date to set, if null the timestamp is set     * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input     * @return integer|string  new datepart     * @throws Zend_Date_Exception     */    public function set($date, $part = null, $locale = null)    {        $zone = $this->getTimezoneFromString($date);        $this->setTimezone($zone);        $result = $this->_calculate('set', $date, $part, $locale);        return $result;    }    /**     * Adds a date or datepart to the existing date, by extracting $part from $date,     * and modifying this object by adding that part.  The $part is then extracted from     * this object and returned as an integer or numeric string (for large values, or $part's     * corresponding to pre-defined formatted date strings).     * This could be for example a ISO 8601 date, the hour the monthname or only the minute.     * There are about 50 different supported date parts.     * For a complete list of supported datepart values look into the docu.     *     * @param  string|integer|array|Zend_Date  $date    Date or datepart to add     * @param  string                          $part    OPTIONAL Part of the date to add, if null the timestamp is added     * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input     * @return integer|string  new datepart     * @throws Zend_Date_Exception     */    public function add($date, $part = null, $locale = null)    {        $this->_calculate('add', $date, $part, $locale);        $result = $this->get($part, $locale);        return $result;    }    /**     * Subtracts a date from another date.     * This could be for example a RFC2822 date, the time,     * the year or only the timestamp. There are about 50 different supported date parts.     * For a complete list of supported datepart values look into the docu     * Be aware: Adding -2 Months is not equal to Subtracting 2 Months !!!     *     * @param  string|integer|array|Zend_Date  $date    Date or datepart to subtract     * @param  string                          $part    OPTIONAL Part of the date to sub, if null the timestamp is subtracted     * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input     * @return integer|string  new datepart     * @throws Zend_Date_Exception     */    public function sub($date, $part = null, $locale = null)    {        $this->_calculate('sub', $date, $part, $locale);        $result = $this->get($part, $locale);        return $result;    }    /**     * Compares a date or datepart with the existing one.     * Returns -1 if earlier, 0 if equal and 1 if later.     *     * @param  string|integer|array|Zend_Date  $date    Date or datepart to compare with the date object     * @param  string                          $part    OPTIONAL Part of the date to compare, if null the timestamp is subtracted     * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input     * @return integer  0 = equal, 1 = later, -1 = earlier     * @throws Zend_Date_Exception     */    public function compare($date, $part = null, $locale = null)    {        $compare = $this->_calculate('cmp', $date, $part, $locale);        if ($compare > 0) {            return 1;        } else if ($compare < 0) {            return -1;        }        return 0;    }    /**     * Returns a new instance of Zend_Date with the selected part copied.     * To make an exact copy, use PHP's clone keyword.     * For a complete list of supported date part values look into the docu.     * If a date part is copied, all other date parts are set to standard values.     * For example: If only YEAR is copied, the returned date object is equal to     * 01-01-YEAR 00:00:00 (01-01-1970 00:00:00 is equal to timestamp 0)     * If only HOUR is copied, the returned date object is equal to     * 01-01-1970 HOUR:00:00 (so $this contains a timestamp equal to a timestamp of 0 plus HOUR).     *     * @param  string              $part    Part of the date to compare, if null the timestamp is subtracted     * @param  string|Zend_Locale  $locale  OPTIONAL New object's locale.  No adjustments to timezone are made.     * @return Zend_Date     */    public function copyPart($part, $locale = null)    {        $clone = clone $this;           // copy all instance variables        $clone->setUnixTimestamp(0);    // except the timestamp        if ($locale != null) {            $clone->setLocale($locale); // set an other locale if selected        }        $clone->set($this, $part);        return $clone;    }    /**     * Internal function, returns the offset of a given timezone     *     * @param string $zone     * @return integer     */    public function getTimezoneFromString($zone)    {        if (is_array($zone)) {            return $this->getTimezone();        }        if ($zone instanceof Zend_Date) {            return $zone->getTimezone();        }        preg_match('/([+-]\d{2}):{0,1}\d{2}/', $zone, $match);        if (!empty($match) and ($match[count($match) - 1] <= 12) and ($match[count($match) - 1] >= -12)) {            $zone = "Etc/GMT";            $zone .= ($match[count($match) - 1] < 0) ? "+" : "-";            $zone .= (int) abs($match[count($match) - 1]);            return $zone;        }        preg_match('/(\w{3,30})/', $zone, $match);        try {            if (!empty($match)) {                $oldzone = $this->getTimezone();                $result = $this->setTimezone($match[count($match) - 1]);                $this->setTimezone($oldzone);                if ($result !== $oldzone) {                    return $match[count($match) - 1];                }            }        } catch (Exception $e) {            // fall through        }        return $this->getTimezone();   }    /**     * Calculates the date or object     *     * @param  string                    $calc  Calculation to make     * @param  string|integer            $date  Date for calculation     * @param  string|integer            $comp  Second date for calculation     * @param  boolean|integer           $dst   Use dst correction if option is set

⌨️ 快捷键说明

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