Methods
-
date
Returns date as string according to the specified format.
-
format
Returns time as string according to the specified format.
-
getDefaultTimeZone
Returns the default time zone using PHP function
date_default_timezone_get
. -
getFormat
Returns format strings for PHP function
date
corresponding to formats used by Webasyst framework. -
getFormatJS
Returns format strings for date/time formatting by means of JavaScript code corresponding to formats used by Webasyst framework.
-
getTimeZones
Returns the list of available time zones with localized descriptions.
-
parse
Returns time value, formatted using one of the formats supported by Webasyst framework, as a string acceptable by standard PHP functions.
public static function date ($format, $time = null, $timezone = null, $locale = null)
Returns date as string according to the specified format.
Parameters
-
$format
Date format. Format symbols acceptable for PHP function
date
are supported. To display month name in lowercase, character f should be used. -
$time
Unix timestamp. If not specified, current timestamp is used.
-
$timezone
Time zone identifier. If not specified, the time zone is determined automatically.
-
$locale
Locale identifier. If not specified, the current user locale is determined automatically.
Example
waDateTime::date('F j, Y', '06-11-2013')
Result
November 6, 2013
public static function format ($format, $time = null, $timezone = null, $locale = null)
Returns time as string according to the specified format.
Parameters
-
$format
Date/time format. The following format strings are acceptable:
humandatetime
: adds words "yesterday", "today", "tomorrow" instead of appropriate dates relative to the current user datehumandate
: returns the date in formatd f Y
supported by methoddate
(format strings listed below are also supported by that method)date
: returns date/time in formatY-m-d
time
: returns date/time in formatH:i
fulltime
: returns date/time in formatH:i:s
datetime
: returns date/time in formatY-m-d H:i
fulldatetime
: returns date/time in formatY-m-d H:i:s
timestamp
: returns date/time in formatU
-
$time
Unix timestamp. If not specified, current timestamp is used.
-
$timezone
Time zone identifier. If not specified, the time zone is determined automatically.
-
$locale
Locale identifier. If not specifed, the current user locale is determined automatically.
Example
waDateTime::format('humandatetime')
Result
Today 17:11
PHP functions
function wa_date ($format, $time = null, $timezone = null, $locale = null)
Wrapper for method format.
Example
wa_date('humandatetime')
Result
Today 17:11
Smarty modifiers
{$timestamp |wa_date [:format='date' :$timezone=null :$locale=null]}
Formats a timestamp using method format. By default, format string date
is used.
Example
{'1384761717'|wa_date}
Result
11/18/2013
{$timestamp |wa_datetime [:format='datetime' :$timezone=null :$locale=null]}
Formats a timestamp using method format. By default, format string datetime
is used..
Example
{'1384761717'|wa_datetime}
Result
11/18/2013 12:01
public static function getDefaultTimeZone()
Returns the default time zone using PHP function date_default_timezone_get
.
Example
waDateTime::getDefaultTimeZone()
Result
America/New_York
public static function getFormat ($format, $locale = null)
Returns format strings for PHP function date
corresponding to formats used by Webasyst framework.
Parameters
-
$format
Time format strings used in Webasyst framework including the following options: sub-array
date_formats
keys specified in config file located inwa-system/locale/data/
, PHP classDateTime
constants, format strings acceptable for PHP functiondate
, or one of the identifiers corresponding to pre-defined time formatting strings supported by method format. -
$locale
Locale identifier. If not specifed, the current user locale is determined automatically.
Example
waDateTime::getFormat ('humandate', 'en_US')
Result
F j, Y
public static function getFormatJS ($format, $locale = null)
Returns format strings for date/time formatting by means of JavaScript code corresponding to formats used by Webasyst framework.
Parameters
-
$format
Format string accepted by parameter
$format
of method getFormat. -
$locale
Locale identifier. If not specifed, the current user locale is determined automatically.
Example
waDateTime::getFormatJS ('humandate', 'en_US')
Result
MM d, yy
public static function getTimeZones()
Returns the list of available time zones with localized descriptions.
Example
waDateTime::getTimeZones()
Result
Array ( [Pacific/Apia] => −11 Apia, Midway, Niue, Pago Pago [Pacific/Fakaofo] => −10 Fakaofo, Honolulu, Johnston, Rarotonga, Tahiti [America/Adak] => −09 Adak [Pacific/Gambier] => −09 Gambier, Marquesas [America/Anchorage] => −08 Anchorage, Juneau, Nome, Sitka, Yakutat [Pacific/Pitcairn] => −08 Pitcairn [America/Dawson] => −07 Dawson, Dawson Creek, Hermosillo, Los Angeles, Metlakatla ... [Pacific/Efate] => +11 Efate, Guadalcanal, Kosrae, Norfolk, Noumea [Pacific/Pohnpei] => +11 Pohnpei [Antarctica/McMurdo] => +12 McMurdo, South Pole [Asia/Anadyr] => +12 Anadyr, Kamchatka, Magadan [Pacific/Auckland] => +12 Auckland, Chatham, Fiji, Funafuti, Kwajalein [Pacific/Majuro] => +12 Majuro, Nauru, Tarawa, Wake, Wallis [Pacific/Enderbury] => +13 Enderbury, Tongatapu [Pacific/Kiritimati] => +14 Kiritimati )
public static function parse ($format, $string, $timezone = null, $locale = null)
Returns time value, formatted using one of the formats supported by Webasyst framework, as a string acceptable by standard PHP functions.
Parameters
-
$format
Format string accepted by format except for
humandatetime
. -
$string
Date/time value string formatted to match the format identifier specified in
$format
parameter. -
$timezone
Time zone identifier. If not specified, the time zone is determined automatically.
-
$locale
Locale identifier. If not specifed, the current user locale is determined automatically.
Example
waDateTime::parse ('humandate', 'November 8, 2013', null, 'en_US')
Result
2013-11-08
PHP functions
function wa_parse_date ($format, $string, $timezone = null, $locale = null)
Wrapper for calling method parse.
Example
wa_parse_date ('humandate', 'November 8, 2013', null, 'en_US')
Result
2013-11-08