📄 date.php
字号:
* @throws Zend_Date_Exception */ public function setTimestamp($timestamp) { return $this->_timestamp('set', $timestamp); } /** * Adds a timestamp * * @param integer|string|array|Zend_Date $timestamp Timestamp to add * @return Zend_Date * @throws Zend_Date_Exception */ public function addTimestamp($timestamp) { return $this->_timestamp('add', $timestamp); } /** * Subtracts a timestamp * * @param integer|string|array|Zend_Date $timestamp Timestamp to sub * @return Zend_Date * @throws Zend_Date_Exception */ public function subTimestamp($timestamp) { return $this->_timestamp('sub', $timestamp); } /** * Compares two timestamps, returning the difference as integer * * @param integer|string|array|Zend_Date $timestamp Timestamp to compare * @return integer 0 = equal, 1 = later, -1 = earlier * @throws Zend_Date_Exception */ public function compareTimestamp($timestamp) { return $this->_timestamp('cmp', $timestamp); } /** * Returns a string representation of the object * Supported format tokens are: * G - era, y - year, Y - ISO year, M - month, w - week of year, D - day of year, d - day of month * E - day of week, e - number of weekday (1-7), h - hour 1-12, H - hour 0-23, m - minute, s - second * A - milliseconds of day, z - timezone, Z - timezone offset, S - fractional second, a - period of day * * Additionally format tokens but non ISO conform are: * SS - day suffix, eee - php number of weekday(0-6), ddd - number of days per month * l - Leap year, B - swatch internet time, I - daylight saving time, X - timezone offset in seconds * r - RFC2822 format, U - unix timestamp * * Not supported ISO tokens are * u - extended year, Q - quarter, q - quarter, L - stand alone month, W - week of month * F - day of week of month, g - modified julian, c - stand alone weekday, k - hour 0-11, K - hour 1-24 * v - wall zone * * @param string $format OPTIONAL Rule for formatting output. If null the default date format is used * @param string $type OPTIONAL Type for the format string which overrides the standard setting * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input * @return string */ public function toString($format = null, $type = null, $locale = null) { if ((strlen($format) != 2) and (Zend_Locale::isLocale($format))) { $locale = $format; $format = null; } if (Zend_Locale::isLocale($type)) { $locale = $type; $type = null; } if ($locale === null) { $locale = $this->getLocale(); } if ($format === null) { $format = Zend_Locale_Format::getDateFormat($locale) . ' ' . Zend_Locale_Format::getTimeFormat($locale); } else if (((self::$_Options['format_type'] == 'php') && ($type === null)) or ($type == 'php')) { $format = Zend_Locale_Format::convertPhpToIsoFormat($format); } // get format tokens $j = 0; $comment = false; $output = array(); for($i = 0; $i < strlen($format); ++$i) { if ($format[$i] == "'") { if ($comment == false) { $comment = true; ++$j; $output[$j] = "'"; } else if (isset($format[$i+1]) and ($format[$i+1] == "'")) { $output[$j] .= "'"; ++$i; } else { $comment = false; } continue; } if (isset($output[$j]) and ($output[$j][0] == $format[$i]) or ($comment == true)) { $output[$j] .= $format[$i]; } else { ++$j; $output[$j] = $format[$i]; } } $notset = false; // fill format tokens with date information for($i = 1; $i <= count($output); ++$i) { // fill fixed tokens switch ($output[$i]) { // special formats case 'SS' : $output[$i] = $this->date('S', $this->getUnixTimestamp(), false); break; case 'eee' : $output[$i] = $this->date('N', $this->getUnixTimestamp(), false); break; case 'ddd' : $output[$i] = $this->date('t', $this->getUnixTimestamp(), false); break; case 'l' : $output[$i] = $this->date('L', $this->getUnixTimestamp(), false); break; case 'B' : $output[$i] = $this->date('B', $this->getUnixTimestamp(), false); break; case 'I' : $output[$i] = $this->date('I', $this->getUnixTimestamp(), false); break; case 'X' : $output[$i] = $this->date('Z', $this->getUnixTimestamp(), false); break; case 'r' : $output[$i] = $this->date('r', $this->getUnixTimestamp(), false); break; case 'U' : $output[$i] = $this->getUnixTimestamp(); break; // eras case 'GGGGG' : $output[$i] = substr($this->get(Zend_Date::ERA, $locale), 0, 1) . "."; break; case 'GGGG' : $output[$i] = $this->get(Zend_Date::ERA_NAME, $locale); break; case 'GGG' : case 'GG' : case 'G' : $output[$i] = $this->get(Zend_Date::ERA, $locale); break; // years case 'yy' : $output[$i] = str_pad($this->get(Zend_Date::YEAR_SHORT, $locale), 2, '0', STR_PAD_LEFT); break; // ISO years case 'YY' : $output[$i] = str_pad($this->get(Zend_Date::YEAR_SHORT_8601, $locale), 2, '0', STR_PAD_LEFT); break; // months case 'MMMMM' : $output[$i] = substr($this->get(Zend_Date::MONTH_NAME_NARROW, $locale), 0, 1); break; case 'MMMM' : $output[$i] = $this->get(Zend_Date::MONTH_NAME, $locale); break; case 'MMM' : $output[$i] = $this->get(Zend_Date::MONTH_NAME_SHORT, $locale); break; case 'MM' : $output[$i] = $this->get(Zend_Date::MONTH, $locale); break; case 'M' : $output[$i] = $this->get(Zend_Date::MONTH_SHORT, $locale); break; // week case 'ww' : $output[$i] = str_pad($this->get(Zend_Date::WEEK, $locale), 2, '0', STR_PAD_LEFT); break; case 'w' : $output[$i] = $this->get(Zend_Date::WEEK, $locale); break; // monthday case 'dd' : $output[$i] = $this->get(Zend_Date::DAY, $locale); break; case 'd' : $output[$i] = $this->get(Zend_Date::DAY_SHORT, $locale); break; // yearday case 'DDD' : $output[$i] = str_pad($this->get(Zend_Date::DAY_OF_YEAR, $locale), 3, '0', STR_PAD_LEFT); break; case 'DD' : $output[$i] = str_pad($this->get(Zend_Date::DAY_OF_YEAR, $locale), 2, '0', STR_PAD_LEFT); break; case 'D' : $output[$i] = $this->get(Zend_Date::DAY_OF_YEAR, $locale); break; // weekday case 'EEEEE' : $output[$i] = $this->get(Zend_Date::WEEKDAY_NARROW, $locale); break; case 'EEEE' : $output[$i] = $this->get(Zend_Date::WEEKDAY, $locale); break; case 'EEE' : $output[$i] = $this->get(Zend_Date::WEEKDAY_SHORT, $locale); break; case 'EE' : $output[$i] = $this->get(Zend_Date::WEEKDAY_NAME, $locale); break; case 'E' : $output[$i] = $this->get(Zend_Date::WEEKDAY_NARROW, $locale); break; // weekday number case 'ee' : $output[$i] = str_pad($this->get(Zend_Date::WEEKDAY_8601, $locale), 2, '0', STR_PAD_LEFT); break; case 'e' : $output[$i] = $this->get(Zend_Date::WEEKDAY_8601, $locale); break; // period case 'a' : $output[$i] = $this->get(Zend_Date::MERIDIEM, $locale); break; // hour case 'hh' : $output[$i] = $this->get(Zend_Date::HOUR_AM, $locale); break; case 'h' : $output[$i] = $this->get(Zend_Date::HOUR_SHORT_AM, $locale); break; case 'HH' : $output[$i] = $this->get(Zend_Date::HOUR, $locale); break; case 'H' : $output[$i] = $this->get(Zend_Date::HOUR_SHORT, $locale); break; // minute case 'mm' : $output[$i] = $this->get(Zend_Date::MINUTE, $locale); break; case 'm' : $output[$i] = $this->get(Zend_Date::MINUTE_SHORT, $locale); break; // second case 'ss' : $output[$i] = $this->get(Zend_Date::SECOND, $locale); break; case 's' : $output[$i] = $this->get(Zend_Date::SECOND_SHORT, $locale); break; case 'S' : $output[$i] = $this->get(Zend_Date::MILLISECOND, $locale); break; // zone // @todo v needs to be reworked as it's the long wall time and not the timezone case 'vvvv' : case 'zzzz' : $output[$i] = $this->get(Zend_Date::TIMEZONE_NAME, $locale); break; // @todo v needs to be reworked as it's the short wall time and not the timezone case 'v' : case 'zzz' : case 'zz' :
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -