Zend_Date::HOUR 的操作 函数/输入 描述 原始日期 效果/输出 get(Zend_Date::HOUR)Output of the hour2009-02-13T14:53:27+01:0014set(12, Zend_Date::HOUR)Set new hour2009-02-13T14:53:27+01:002009-02-13T12:53:27+01:00add(12, Zend_Date::HOUR)Add hours2009-02-13T14:53:27+01:002009-02-14T02:53:27+01:00sub(12, Zend_Date::HOUR)Subtract hours2009-02-13T14:53:27+01:002009-02-13T02:53:27+01:00compare(12, Zend_Date::HOUR)Compare hour, returns 0, 1 or -12009-02-13T14:53:27+01:001 (if object > argument)copy(Zend_Date::HOUR)Copies only the hour part2009-02-13T14:53:27+01:001970-01-01T14:00:00+01:00equals(14, Zend_Date::HOUR)Compares the hour, returns TRUE or FALSE2009-02-13T14:53:27+01:00TRUEisEarlier(12, Zend_Date::HOUR)Compares the hour, returns TRUE or FALSE2009-02-13T14:53:27+01:00TRUEisLater(12, Zend_Date::HOUR)Compares the hour, returns TRUE or FALSE2009-02-13T14:53:27+01:00FALSE
Day Constants 常数 描述 日期 受影响部分/例子 Zend_Date::DAYDay (as a number, two digit)2009-02-06T14:53:27+01:002009-02-06T14:53:27+01:00 (06)Zend_Date::DAY_SHORTDay (as a number, one or two digit)2009-02-06T14:53:27+01:002009-02-06T14:53:27+01:00 (6)Zend_Date::WEEKDAYWeekday (Name of the day, localized, complete)2009-02-06T14:53:27+01:00FridayZend_Date::WEEKDAY_SHORTWeekday (Name of the day, localized, abbreviated, the first three digits)2009-02-06T14:53:27+01:00Fre for FridayZend_Date::WEEKDAY_NAMEWeekday (Name of the day, localized, abbreviated, the first two digits)2009-02-06T14:53:27+01:00Fr for FridayZend_Date::WEEKDAY_NARROWWeekday (Name of the day, localized, abbreviated, only the first digit)2009-02-06T14:53:27+01:00F for FridayZend_Date::WEEKDAY_DIGITWeekday (0 = Sunday, 6 = Saturday)2009-02-06T14:53:27+01:005 for FridayZend_Date::WEEKDAY_8601Weekday according to ISO 8601 (1 = Monday, 7 = Sunday)2009-02-06T14:53:27+01:005 for FridayZend_Date::DAY_OF_YEARDay (as a number, one or two digit)2009-02-06T14:53:27+01:0043Zend_Date::DAY_SUFFIXEnglish addendum for the day (st, nd, rd, th)2009-02-06T14:53:27+01:00th
星期常数 常数 描述 日期 受影响部分/例子 Zend_Date::WEEKWeek (as a number, 1-53)2009-02-06T14:53:27+01:007
月常数 常数 描述 日期 受影响部分/例子 Zend_Date::MONTH_NAMEMonth (Name of the month, localized, complete)2009-02-06T14:53:27+01:00FebruaryZend_Date::MONTH_NAME_SHORTMonth (Name of the month, localized, abbreviated, three digit)2009-02-06T14:53:27+01:00FebZend_Date::MONTH_NAME_NARROWMonth (Name of the month, localized, abbreviated, one digit)2009-02-06T14:53:27+01:00FZend_Date::MONTHMonth (Number of the month, two digit)2009-02-06T14:53:27+01:002009-02-06T14:53:27+01:00 (02)Zend_Date::MONTH_SHORTMonth (Number of the month, one or two digit)2009-02-06T14:53:27+01:002009-02-06T14:53:27+01:00 (2)Zend_Date::MONTH_DAYSNumber of days for this month (number)2009-02-06T14:53:27+01:0028
年常数 常数 描述 日期 受影响部分/例子 Zend_Date::YEARYear (number)2009-02-06T14:53:27+01:002009-02-06T14:53:27+01:00Zend_Date::YEAR_8601Year according to ISO 8601 (number)2009-02-06T14:53:27+01:002009Zend_Date::YEAR_SHORTYear (number, two digit)2009-02-06T14:53:27+01:002009-02-06T14:53:27+01:00Zend_Date::YEAR_SHORT_8601Year according to ISO 8601 (number, two digit)2009-02-06T14:53:27+01:0009Zend_Date::LEAPYEARIs the year a leap year? (TRUE or FALSE)2009-02-06T14:53:27+01:00FALSE
时间常数 常数 描述 日期 受影响部分/例子 Zend_Date::HOURHour (00-23, two digit)2009-02-06T14:53:27+01:0014Zend_Date::HOUR_SHORTHour (0-23, one or two digit)2009-02-06T14:53:27+01:0014Zend_Date::HOUR_SHORT_AMHour (1-12, one or two digit)2009-02-06T14:53:27+01:002Zend_Date::HOUR_AMHour (01-12, two digit)2009-02-06T14:53:27+01:0002Zend_Date::MINUTEMinute (00-59, two digit)2009-02-06T14:53:27+01:002009-02-06T14:53:27+01:00Zend_Date::MINUTE_SHORTMinute (0-59, one or two digit)2009-02-06T14:03:27+01:002009-02-06T14:03:27+01:00Zend_Date::SECONDSecond (00-59, two digit)2009-02-06T14:53:27+01:002009-02-06T14:53:27+01:00Zend_Date::SECOND_SHORTSecond (0-59, one or two digit)2009-02-06T14:53:07+01:002009-02-06T14:53:07+01:00Zend_Date::MILLISECONDMillisecond (theoretically infinite)2009-02-06T14:53:27.205462009-02-06T14:53:27.20546Zend_Date::MERIDIEMTime of day (forenoon/afternoon)2009-02-06T14:53:27+01:00afternoonZend_Date::SWATCHSwatch Internet Time2009-02-06T14:53:27+01:00620
时区常数 常数 描述 日期 受影响部分/例子 Zend_Date::TIMEZONEName der time zone (string, abbreviated)2009-02-06T14:53:27+01:00CETZend_Date::TIMEZONE_NAMEName of the time zone (string, complete)2009-02-06T14:53:27+01:00Europe/ParisZend_Date::TIMEZONE_SECSDifference of the time zone to GMT in seconds (integer)2009-02-06T14:53:27+01:003600 seconds to GMTZend_Date::GMT_DIFFDifference to GMT in seconds (string)2009-02-06T14:53:27+01:00+0100Zend_Date::GMT_DIFF_SEPDifference to GMT in seconds (string, separated)2009-02-06T14:53:27+01:00+01:00Zend_Date::DAYLIGHTSummer time or Winter time? (TRUE or FALSE)2009-02-06T14:53:27+01:00FALSE
日期格式常数(格式包括时区) 常数 描述 日期 受影响部分/例子 Zend_Date::ISO_8601Date according to ISO 8601 (string, complete)2009-02-13T14:53:27+01:002009-02-13T14:53:27+01:00Zend_Date::RFC_2822Date according to RFC 2822 (string)2009-02-13T14:53:27+01:00Fri, 13 Feb 2009 14:53:27 +0100Zend_Date::TIMESTAMPUnix time (seconds since 1.1.1970, mixed)2009-02-13T14:53:27+01:001234533207Zend_Date::ATOMDate according to ATOM (string)2009-02-13T14:53:27+01:002009-02-13T14:53:27+01:00Zend_Date::COOKIEDate for Cookies (string, for Cookies)2009-02-13T14:53:27+01:00Friday, 13-Feb-09 14:53:27 Europe/ParisZend_Date::RFC_822Date according to RFC 822 (string)2009-02-13T14:53:27+01:00Fri, 13 Feb 09 14:53:27 +0100Zend_Date::RFC_850Date according to RFC 850 (string)2009-02-13T14:53:27+01:00Friday, 13-Feb-09 14:53:27 Europe/ParisZend_Date::RFC_1036Date according to RFC 1036 (string)2009-02-13T14:53:27+01:00Fri, 13 Feb 09 14:53:27 +0100Zend_Date::RFC_1123Date according to RFC 1123 (string)2009-02-13T14:53:27+01:00Fri, 13 Feb 2009 14:53:27 +0100Zend_Date::RSSDate for RSS Feeds (string)2009-02-13T14:53:27+01:00Fri, 13 Feb 2009 14:53:27 +0100Zend_Date::W3CDate for HTML/HTTP according to W3C (string)2009-02-13T14:53:27+01:002009-02-13T14:53:27+01:00
日期和时间格式 (format varies by locale) 常数 描述 日期 受影响部分/例子 Zend_Date::ERAEpoch (string, localized, abbreviated)2009-02-06T14:53:27+01:00AD (anno Domini)Zend_Date::ERA_NAMEEpoch (string, localized, complete)2009-02-06T14:53:27+01:00anno domini (anno Domini)Zend_Date::DATESStandard date (string, localized, default value).2009-02-13T14:53:27+01:0013.02.2009Zend_Date::DATE_FULLComplete date (string, localized, complete)2009-02-13T14:53:27+01:00Friday, 13. February 2009Zend_Date::DATE_LONGLong date (string, localized, long)2009-02-13T14:53:27+01:0013. February 2009Zend_Date::DATE_MEDIUMNormal date (string, localized, normal)2009-02-13T14:53:27+01:0013.02.2009Zend_Date::DATE_SHORTAbbreviated Date (string, localized, abbreviated)2009-02-13T14:53:27+01:0013.02.09Zend_Date::TIMESStandard time (string, localized, default value)2009-02-13T14:53:27+01:0014:53:27Zend_Date::TIME_FULLComplete time (string, localized, complete)2009-02-13T14:53:27+01:0014:53 Uhr CETZend_Date::TIME_LONGLong time (string, localized, Long)2009-02-13T14:53:27+01:0014:53:27 CETZend_Date::TIME_MEDIUMNormal time (string, localized, normal)2009-02-13T14:53:27+01:0014:53:27Zend_Date::TIME_SHORTAbbreviated time (string, localized, abbreviated)2009-02-13T14:53:27+01:0014:53
自定义 ISO 输出格式
如果你需要的日期格式没有在上述的格式中出现,那么使用从下面 ISO 格式指定器产生的自定义格式。
下面的例子示例了从下列表中生成的自定义 ISO 格式的常量的用法。格式长度无限制。并且允许格式常量的多重用法。
如果你喜欢的话,可接受的格式指定器可以从 ISO 格式修改为 PHP 的日期格式,然而,PHP 日期格式指定不支持所有的按 ISO 标准定义的格式。
使用 Zend_Date::setOptions(array('format_type' => 'php')) 方法来把 Zend_Date 方法从支持 ISO 格式制定器切换到 PHP date()类型制定器(参见下面 )。
自定义 ISO 格式用法示例 toString("'Era:GGGG='GGGG, ' Date:yy.MMMM.dd'yy.MMMM.dd");
]]>
ISO 8601 日期输出 常量
常数 描述 日期 受影响部分/例子 GEpoch, localized, abbreviatedZend_Date::ERAADGGEpoch, localized, abbreviatedZend_Date::ERAADGGGEpoch, localized, abbreviatedZend_Date::ERAADGGGGEpoch, localized, completeZend_Date::ERA_NAMEanno dominiGGGGGEpoch, localized, abbreviatedZend_Date::ERAayYear, at least one digitZend_Date::YEAR9yyYear, at least two digitZend_Date::YEAR_SHORT09yyyYear, at least three digitZend_Date::YEAR2009yyyyYear, at least four digitZend_Date::YEAR2009yyyyyYear, at least five digitZend_Date::YEAR02009YYear according to ISO 8601, at least one digitZend_Date::YEAR_86019YYYear according to ISO 8601, at least two digitZend_Date::YEAR_SHORT_860109YYYYear according to ISO 8601, at least three digitZend_Date::YEAR_86012009YYYYYear according to ISO 8601, at least four digitZend_Date::YEAR_86012009YYYYYYear according to ISO 8601, at least five digitZend_Date::YEAR_860102009MMonth, one or two digitZend_Date::MONTH_SHORT2MMMonth, two digitZend_Date::MONTH02MMMMonth, localized, abbreviatedZend_Date::MONTH_NAME_SHORTFebMMMMMonth, localized, completeZend_Date::MONTH_NAMEFebruaryMMMMMMonth, localized, abbreviated, one digitZend_Date::MONTH_NAME_NARROWFwWeek, one or two digitZend_Date::WEEK5wwWeek, two digitZend_Date::WEEK05dDay of the month, one or two digitZend_Date::DAY_SHORT9ddDay of the month, two digitZend_Date::DAY09DDay of the year, one, two or three digitZend_Date::DAY_OF_YEAR7DDDay of the year, two or three digitZend_Date::DAY_OF_YEAR07DDDDay of the year, three digitZend_Date::DAY_OF_YEAR007EDay of the week, localized, abbreviated, one charZend_Date::WEEKDAY_NARROWMEEDay of the week, localized, abbreviated, two charZend_Date::WEEKDAY_NAMEMoEEEDay of the week, localized, abbreviated, three charZend_Date::WEEKDAY_SHORTMonEEEEDay of the week, localized, completeZend_Date::WEEKDAYMondayEEEEEDay of the week, localized, abbreviated, one digitZend_Date::WEEKDAY_NARROWMeNumber of the day, one digitZend_Date::WEEKDAY_NARROW4eeNumber of the day, two digitZend_Date::WEEKDAY_NARROW04aTime of day, localizedZend_Date::MERIDIEMvorm.hHour, (1-12), one or two digitZend_Date::HOUR_SHORT_AM2hhHour, (01-12), two digitZend_Date::HOUR_AM02HHour, (0-23), one or two digitZend_Date::HOUR_SHORT2HHHour, (00-23), two digitZend_Date::HOUR02mMinute, (0-59), one or two digitZend_Date::MINUTE_SHORT2mmMinute, (00-59), two digitZend_Date::MINUTE02sSecond, (0-59), one or two digitZend_Date::SECOND_SHORT2ssSecond, (00-59), two digitZend_Date::SECOND02SMillisecondZend_Date::MILLISECOND20536zTime zone, localized, abbreviatedZend_Date::TIMEZONECETzzTime zone, localized, abbreviatedZend_Date::TIMEZONECETzzzTime zone, localized, abbreviatedZend_Date::TIMEZONECETzzzzTime zone, localized, completeZend_Date::TIMEZONE_NAMEEurope/ParisZDifference of time zoneZend_Date::GMT_DIFF+0100ZZDifference of time zoneZend_Date::GMT_DIFF+0100ZZZDifference of time zoneZend_Date::GMT_DIFF+0100ZZZZDifference of time zone, separatedZend_Date::GMT_DIFF_SEP+01:00AMillisecondZend_Date::MILLISECOND20563
注意缺省的 ISO 格式不同于 PHP 的格式,如果在先前没有使用,PHP 的格式可以迭代。
特别是 Year and Minute 的格式指定器不常按预期来使用。
对于 year 有两个可用的指定器经常发生错误:
ISO 年的Y 指定器和真实年的 y 的指定器。
区别微小但意义重大。
Y 计算 ISO 年,常用于日历格式,例如 the 31. December 2007。
真实年为 2007,但它是 2008 年的第一周的第一天,所以,如果使用 'dd.MM.yyyy' 会得到 '31.December.2007' 但如果使用 'dd.MM.YYYY' 会得到 '31.December.2008'。
正如你所看到的,这不是 bug , 但期望的行为依赖指定器的使用。
对 minute 来说区别不大。ISO 使用 m 指定器,PHP 使用 i。
所以如果没有按你的格式获得分钟数,检查是否使用了正确的指定器。
使用 PHP 的 date() 格式指定器的自定义输出格式
如果你更喜欢使用 PHP 的日期格式指定器,可以使用 Zend_Date::setOptions(array('format' => 'php')) 方法
把 Zend_Date 方法从支持 ISO 格式制定器切换到 PHP date()类型制定器。然后所有参数必需用 PHP's date() 格式指定器 给出。
PHP 日期格式缺乏一些 ISO 格式支持的格式,反之亦然。如果不喜欢,可以使用标准的 ISO 格式。
而且,如果你有一些历史遗留的使用 PHP 日期格式的代码,可以用 Zend_Locale_Format::convertPhpToIsoFormat() 手工转换为 ISO 格式,或使用 setOptions()。
下面的例子示例了从下表生成的自定义格式的常量的用法。
用 PHP 指定器自定义格式的用例 'php'));
$date = new Zend_Date(1234567890, false, $locale);
// outputs something like 'February 16, 2007, 3:36 am'
print $date->toString('F j, Y, g:i a');
print $date->toString("'Format:D M j G:i:s T Y='D M j G:i:s T Y");
]]>
下标列出了带有相应等同的 Zend_Date常量和 CLDR/ISO 格式指定器的 PHP 日期格式指定器。
对一些情况,当 CLDR/ISO 格式没有等同的格式指定器时,PHP 格式指定器不用 Zend_Locale_Format::convertPhpToIsoFormat() 来改变,
并且 Zend_Date 方法承认这些 “奇特的” PHP 格式指定器,即使是处于缺省的 "ISO" 格式模式中。
PHP 日期输出 常量
常数 描述 Corresponds best toclosest CLDR equivalent 受影响部分/例子 dDay of the month, two digitZend_Date::DAYdd09DDay of the week, localized, abbreviated, three digitZend_Date::WEEKDAY_SHORTEEEMonjDay of the month, one or two digitZend_Date::DAY_SHORTd9l (lowercase L)Day of the week, localized, completeZend_Date::WEEKDAYEEEEMondayNNumber of the weekday, one digitZend_Date::WEEKDAY_8601e4SEnglish suffixes for day of month, two charsno equivalentno equivalentstwNumber of the weekday, 0=sunday, 6=saturdayZend_Date::WEEKDAY_DIGITno equivalent4zDay of the year, one, two or three digitZend_Date::DAY_OF_YEARD7WWeek, one or two digitZend_Date::WEEKw5FMonth, localized, completeZend_Date::MONTH_NAMEMMMMFebruarymMonth, two digitZend_Date::MONTHMM02MMonth, localized, abbreviatedZend_Date::MONTH_NAME_SHORTMMMFebnMonth, one or two digitZend_Date::MONTH_SHORTM2tNumber of days per month, one or two digitsZend_Date::MONTH_DAYSno equivalent30LLeapyear, booleanZend_Date::LEAPYEARno equivalenttrueoYear according to ISO 8601, at least four digitZend_Date::YEAR_8601YYYY2009YYear, at least four digitZend_Date::YEARyyyy2009yYear, at least two digitZend_Date::YEAR_SHORTyy09aTime of day, localizedZend_Date::MERIDIEMa (sort of, but likely to be uppercase)vorm.ATime of day, localizedZend_Date::MERIDIEMa (sort of, but no guarantee that the format is uppercase)VORM.BSwatch internet timeZend_Date::SWATCHno equivalent1463gHour, (1-12), one or two digitZend_Date::HOUR_SHORT_AMh2GHour, (0-23), one or two digitZend_Date::HOUR_SHORTH2hHour, (01-12), two digitZend_Date::HOUR_AMhh02HHour, (00-23), two digitZend_Date::HOURHH02iMinute, (00-59), two digitZend_Date::MINUTEmm02sSecond, (00-59), two digitZend_Date::SECONDss02eTime zone, localized, completeZend_Date::TIMEZONE_NAMEzzzzEurope/ParisIDaylightZend_Date::DAYLIGHTno equivalent1ODifference of time zoneZend_Date::GMT_DIFFZ or ZZ or ZZZ+0100PDifference of time zone, separatedZend_Date::GMT_DIFF_SEPZZZZ+01:00TTime zone, localized, abbreviatedZend_Date::TIMEZONEz or zz or zzzCETZTime zone offset in secondsZend_Date::TIMEZONE_SECSno equivalent3600cStandard Iso format outputZend_Date::ISO_8601no equivalent2004-02-12T15:19:21+00:00rStandard Rfc 2822 format outputZend_Date::RFC_2822no equivalentThu, 21 Dec 2000 16:01:07 +0200UUnix timestampZend_Date::TIMESTAMPno equivalent15275422364