Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • CChoiceFormat
  • CDateFormatter
  • CDbMessageSource
  • CGettextMessageSource
  • CLocale
  • CMessageSource
  • CMissingTranslationEvent
  • CNumberFormatter
  • CPhpMessageSource
  • Overview
  • Package
  • Class
  • Tree

Class CDateFormatter

CDateFormatter provides date/time localization functionalities.

CDateFormatter allows you to format dates and times in a locale-sensitive manner. Patterns are interpreted 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:
  • The method CDateFormatter::formatDateTime() formats date or time or both using predefined patterns which include 'full', 'long', 'medium' (default) and 'short'.
  • The method CDateFormatter::format() formats datetime using the specified pattern. See http://www.unicode.org/reports/tr35/#Date_Format_Patterns for details about the recognized pattern characters.
CComponent
Extended by CDateFormatter
Package: system\i18n
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Wei Zhuo <weizhuo[at]gmail[dot]com>
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/i18n/CDateFormatter.php
Methods summary
public
# __construct( mixed $locale )

Constructor.

Constructor.

Parameters

$locale
mixed
$locale locale ID (string) or CLocale instance
public string
# format( string $pattern, mixed $time )

Formats a date according to a customized pattern.

Formats a date according to a customized pattern.

Parameters

$pattern
string
$pattern the pattern (See http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns)
$time
mixed
$time UNIX timestamp or a string in strtotime format

Returns

string
formatted date time. Null if $time is null. (the null value check is available since Yii 1.1.11)
public string
# formatDateTime( mixed $timestamp, string $dateWidth = 'medium', string $timeWidth = 'medium' )

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

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

Parameters

$timestamp
mixed
$timestamp UNIX timestamp or a string in strtotime format
$dateWidth
string
$dateWidth 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
$timeWidth 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

Returns

string
formatted date time.
protected array
# parseFormat( string $pattern )

Parses the datetime format pattern.

Parses the datetime format pattern.

Parameters

$pattern
string
$pattern the pattern to be parsed

Returns

array
tokenized parsing result
protected string
# formatYear( string $pattern, array $date )

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.

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.

Parameters

$pattern
string
$pattern a pattern.
$date
array
$date result of CTimestamp::getdate.

Returns

string
formatted year
protected string
# formatMonth( string $pattern, array $date )

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";

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";

Parameters

$pattern
string
$pattern a pattern.
$date
array
$date result of CTimestamp::getdate.

Returns

string
month name

Throws

CException
if "month" pattern is unknown
protected string
# formatDay( string $pattern, array $date )

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

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

Parameters

$pattern
string
$pattern a pattern.
$date
array
$date result of CTimestamp::getdate.

Returns

string
day of the month

Throws

CException
if "day" pattern is unknown
protected integer
# formatDayInYear( string $pattern, array $date )

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

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

Parameters

$pattern
string
$pattern a pattern.
$date
array
$date result of CTimestamp::getdate.

Returns

integer
hours in AM/PM format.

Throws

CException
is "dayInYear" pattern is unknown
protected integer
# formatDayInMonth( string $pattern, array $date )

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

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

Parameters

$pattern
string
$pattern a pattern.
$date
array
$date result of CTimestamp::getdate.

Returns

integer
day in month

Throws

CException
if "dayInMonth" pattern is unknown

See

http://www.unicode.org/reports/tr35/#Date_Format_Patterns
protected string
# formatDayInWeek( string $pattern, array $date )

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";

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";

Parameters

$pattern
string
$pattern a pattern.
$date
array
$date result of CTimestamp::getdate.

Returns

string
day of the week.

Throws

CException
if "dayInWeek" pattern is unknown

See

http://www.unicode.org/reports/tr35/#Date_Format_Patterns
protected string
# formatPeriod( string $pattern, array $date )

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

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

Parameters

$pattern
string
$pattern a pattern.
$date
array
$date result of CTimestamp::getdate.

Returns

string
AM or PM designator

Throws

CException
if "period" pattern is unknown
protected string
# formatHour24( string $pattern, array $date )

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

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

Parameters

$pattern
string
$pattern a pattern.
$date
array
$date result of CTimestamp::getdate.

Returns

string
hours in 24 hour format.

Throws

CException
if "hour24" pattern is unknown
protected string
# formatHour12( string $pattern, array $date )

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

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

Parameters

$pattern
string
$pattern a pattern.
$date
array
$date result of CTimestamp::getdate.

Returns

string
hours in 12 hour format.

Throws

CException
if "hour12" pattern is unknown
protected integer
# formatHourInDay( string $pattern, array $date )

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

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

Parameters

$pattern
string
$pattern a pattern.
$date
array
$date result of CTimestamp::getdate.

Returns

integer
hours [1-24]

Throws

CException
if "hourInDay" pattern is unknown
protected integer
# formatHourInPeriod( string $pattern, array $date )

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

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

Parameters

$pattern
string
$pattern a pattern.
$date
array
$date result of CTimestamp::getdate.

Returns

integer
hours in AM/PM format.

Throws

CException
if "hourInPeriod" pattern is unknown
protected string
# formatMinutes( string $pattern, array $date )

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

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

Parameters

$pattern
string
$pattern a pattern.
$date
array
$date result of CTimestamp::getdate.

Returns

string
minutes.

Throws

CException
if "minutes" pattern is unknown
protected string
# formatSeconds( string $pattern, array $date )

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

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

Parameters

$pattern
string
$pattern a pattern.
$date
array
$date result of CTimestamp::getdate.

Returns

string
seconds

Throws

CException
if "seconds" pattern is unknown
protected integer
# formatWeekInYear( string $pattern, array $date )

Get the week in the year.

Get the week in the year.

Parameters

$pattern
string
$pattern a pattern.
$date
array
$date result of CTimestamp::getdate.

Returns

integer
week in year

Throws

CException
if "weekInYear" pattern is unknown
protected integer
# formatWeekInMonth( array $pattern, string $date )

Get week in the month.

Get week in the month.

Parameters

$pattern
array
$pattern result of CTimestamp::getdate.
$date
string
$date a pattern.

Returns

integer
week in month

Throws

CException
if "weekInMonth" pattern is unknown
protected string
# formatTimeZone( string $pattern, array $date )

Get the timezone of the server machine.

Get the timezone of the server machine.

Parameters

$pattern
string
$pattern a pattern.
$date
array
$date result of CTimestamp::getdate.

Returns

string
time zone

Throws

CException
if "timeZone" pattern is unknown
protected string
# formatEra( string $pattern, array $date )

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

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

Parameters

$pattern
string
$pattern a pattern.
$date
array
$date result of CTimestamp::getdate.

Returns

string
era

Throws

CException
if "era" pattern is unknown
Methods inherited from CComponent
__call(), __get(), __isset(), __set(), __unset(), asa(), attachBehavior(), attachBehaviors(), attachEventHandler(), canGetProperty(), canSetProperty(), detachBehavior(), detachBehaviors(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), getEventHandlers(), hasEvent(), hasEventHandler(), hasProperty(), raiseEvent()
API documentation generated by ApiGen 2.8.0