system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.i18n system.i18n.gettext system.logging system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers

CDateFormatter

system.i18n
继承 class CDateFormatter » CComponent
可用自 1.0
版本 $Id$
CDateFormatter provides date/time localization functionalities.

CDateFormatter allows you to format dates and times in a locale-sensitive manner. Patterns are interpretted in the locale that the CDateFormatter instance is associated with. For example, month names and weekday names may vary under different locales, which yields different formatting results. The patterns that CDateFormatter recognizes are as defined in CLDR.

CDateFormatter supports predefined patterns as well as customized ones:

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. CComponent
__construct() Constructor. CDateFormatter
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
format() Formats a date according to a customized pattern. CDateFormatter
formatDateTime() Formats a date according to a predefined pattern. CDateFormatter
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
raiseEvent() Raises an event. CComponent

受保护的方法

隐藏继承的方法

方法描述被定义在
formatDay() Get the day of the month. CDateFormatter
formatDayInMonth() Get day of week in the month, e.g. 2nd Wed in July. CDateFormatter
formatDayInWeek() Get the day of the week. CDateFormatter
formatDayInYear() Get the day in the year, e.g. [1-366] CDateFormatter
formatEra() Get the era. i.e. in gregorian, year > 0 is AD, else BC. CDateFormatter
formatHour12() Get the hours in 12 hour format, i.e., [1-12] CDateFormatter
formatHour24() Get the hours in 24 hour format, i.e. [0-23]. CDateFormatter
formatHourInDay() Get the hours [1-24]. CDateFormatter
formatHourInPeriod() Get the hours in AM/PM format, e.g [0-11] CDateFormatter
formatMinutes() Get the minutes. CDateFormatter
formatMonth() Get the month. CDateFormatter
formatPeriod() Get the AM/PM designator, 12 noon is PM, 12 midnight is AM. CDateFormatter
formatSeconds() Get the seconds. CDateFormatter
formatTimeZone() Get the timezone of the server machine. CDateFormatter
formatWeekInMonth() Get week in the month. CDateFormatter
formatWeekInYear() Get the week in the year. CDateFormatter
formatYear() Get the year. CDateFormatter
parseFormat() Parses the datetime format pattern. CDateFormatter

方法详情

__construct() 方法
public void __construct(mixed $locale)
$locale mixed locale ID (string) or CLocale instance

Constructor.

format() 方法
public string format(string $pattern, mixed $time)
$pattern string the pattern (See http://www.unicode.org/reports/tr35/#Date_Format_Patterns)
$time mixed UNIX timestamp or a string in strtotime format
{return} string formatted date time.

Formats a date according to a customized pattern.

formatDateTime() 方法
public string formatDateTime(mixed $timestamp, string $dateWidth='medium', string $timeWidth='medium')
$timestamp mixed UNIX timestamp or a string in strtotime format
$dateWidth string width of the date pattern. It can be 'full', 'long', 'medium' and 'short'. If null, it means the date portion will NOT appear in the formatting result
$timeWidth string width of the time pattern. It can be 'full', 'long', 'medium' and 'short'. If null, it means the time portion will NOT appear in the formatting result
{return} string formatted date time.

Formats a date according to a predefined pattern. The predefined pattern is determined based on the date pattern width and time pattern width.

formatDay() 方法
protected string formatDay(string $pattern, array $date)
$pattern string a pattern.
$date array result of CTimestamp::getdate.
{return} string day of the month

Get the day of the month. "d" for non-padding, "dd" will always return 2 digits day numbers, e.g. 05.

formatDayInMonth() 方法
protected int formatDayInMonth(string $pattern, array $date)
$pattern string a pattern.
$date array result of CTimestamp::getdate.
{return} int day in month

Get day of week in the month, e.g. 2nd Wed in July.

formatDayInWeek() 方法
protected string formatDayInWeek(string $pattern, array $date)
$pattern string a pattern.
$date array result of CTimestamp::getdate.
{return} string day of the week.

Get the day of the week. "E", "EE", "EEE" will return abbreviated week day name, e.g. "Tues"; "EEEE" will return full week day name; "EEEEE" will return the narrow week day name, e.g. "T";

formatDayInYear() 方法
protected int formatDayInYear(string $pattern, array $date)
$pattern string a pattern.
$date array result of CTimestamp::getdate.
{return} int hours in AM/PM format.

Get the day in the year, e.g. [1-366]

formatEra() 方法
protected string formatEra(string $pattern, array $date)
$pattern string a pattern.
$date array result of CTimestamp::getdate.
{return} string era

Get the era. i.e. in gregorian, year > 0 is AD, else BC.

formatHour12() 方法
protected string formatHour12(string $pattern, array $date)
$pattern string a pattern.
$date array result of CTimestamp::getdate.
{return} string hours in 12 hour format.

Get the hours in 12 hour format, i.e., [1-12] "h" for non-padding, "hh" will always return 2 characters.

formatHour24() 方法
protected string formatHour24(string $pattern, array $date)
$pattern string a pattern.
$date array result of CTimestamp::getdate.
{return} string hours in 24 hour format.

Get the hours in 24 hour format, i.e. [0-23]. "H" for non-padding, "HH" will always return 2 characters.

formatHourInDay() 方法
protected int formatHourInDay(string $pattern, array $date)
$pattern string a pattern.
$date array result of CTimestamp::getdate.
{return} int hours [1-24]

Get the hours [1-24]. 'k' for non-padding, and 'kk' with 2 characters padding.

formatHourInPeriod() 方法
protected int formatHourInPeriod(string $pattern, array $date)
$pattern string a pattern.
$date array result of CTimestamp::getdate.
{return} int hours in AM/PM format.

Get the hours in AM/PM format, e.g [0-11] "K" for non-padding, "KK" will always return 2 characters.

formatMinutes() 方法
protected string formatMinutes(string $pattern, array $date)
$pattern string a pattern.
$date array result of CTimestamp::getdate.
{return} string minutes.

Get the minutes. "m" for non-padding, "mm" will always return 2 characters.

formatMonth() 方法
protected string formatMonth(string $pattern, array $date)
$pattern string a pattern.
$date array result of CTimestamp::getdate.
{return} string month name

Get the month. "M" will return integer 1 through 12; "MM" will return two digits month number with necessary zero padding, e.g. 05; "MMM" will return the abrreviated month name, e.g. "Jan"; "MMMM" will return the full month name, e.g. "January"; "MMMMM" will return the narrow month name, e.g. "J";

formatPeriod() 方法
protected string formatPeriod(string $pattern, array $date)
$pattern string a pattern.
$date array result of CTimestamp::getdate.
{return} string AM or PM designator

Get the AM/PM designator, 12 noon is PM, 12 midnight is AM.

formatSeconds() 方法
protected string formatSeconds(string $pattern, array $date)
$pattern string a pattern.
$date array result of CTimestamp::getdate.
{return} string seconds

Get the seconds. "s" for non-padding, "ss" will always return 2 characters.

formatTimeZone() 方法
protected string formatTimeZone(string $pattern, array $date)
$pattern string a pattern.
$date array result of CTimestamp::getdate.
{return} string time zone

Get the timezone of the server machine.

formatWeekInMonth() 方法
protected int formatWeekInMonth(array $pattern, string $date)
$pattern array result of CTimestamp::getdate.
$date string a pattern.
{return} int week in month

Get week in the month.

formatWeekInYear() 方法
protected int formatWeekInYear(string $pattern, array $date)
$pattern string a pattern.
$date array result of CTimestamp::getdate.
{return} int week in year

Get the week in the year.

formatYear() 方法
protected string formatYear(string $pattern, array $date)
$pattern string a pattern.
$date array result of CTimestamp::getdate.
{return} string formatted year

Get the year. "yy" will return the last two digits of year. "y...y" will pad the year with 0 in the front, e.g. "yyyyy" will generate "02008" for year 2008.

parseFormat() 方法
protected array parseFormat(string $pattern)
$pattern string the pattern to be parsed
{return} array tokenized parsing result

Parses the datetime format pattern.