public class DateTimeObj

class.datetimeobj.php #14

The DateTimeObj provides static functions regarding dates in Symphony. Symphony will set the default timezone of the system using the value from the Configuration values. Alternatively a new settings can be set using the setSettings function. Symphony parses all input dates against the Configuration date formats by default for better support with non English dates.

Methods

static string|boolean format(string $string, string $format, boolean $localize, string $timezone)

Formats the given date and time $string based on the given $format. Optionally the result will be localized and respect a timezone differing from the system default. The default output is ISO 8601. Please note that for best compatibility with European dates it is recommended that your site be in a PHP5.3 environment.

Parameters
  • $string string(optional) A string containing date and time, defaults to the current date and time

  • $format string(optional) A valid PHP date format, defaults to ISO 8601

  • $localize boolean(optional) Localizes the output, if true, defaults to true

  • $timezone string(optional) The timezone associated with the timestamp

Returns

The formatted date, or if the date could not be parsed, false.

static string|boolean get(string $format, integer $timestamp, string $timezone)

Given a $format, and a $timestamp, return the date in the format provided. This function is a basic wrapper for PHP's DateTime object. If the $timestamp is omitted, the current timestamp will be used. Optionally, you pass a timezone identifier with this function to localise the output

If you like to display a date in the backend, please make use of DateTimeObj::format() which allows date and time localization

Parameters
  • $format stringA valid PHP date format

  • $timestamp integer(optional) A unix timestamp to format. 'now' or omitting this parameter will result in the current time being used

  • $timezone string(optional) The timezone associated with the timestamp

Returns

The formatted date, of if the date could not be parsed, false.

See Also
static array getDateFormats()

Returns an array of the date formats Symphony supports. These formats are a combination of valid PHP format tokens.

See Also
static array getDateFormatsSelectOptions(string $selected)

Returns an array of the date formats Symphony supports by applying the format to the current datetime. The array returned is for use with Widget::Select()

Parameters
  • $selected stringA preselected date format, defaults to null

Returns

An associative array, for use with Widget::Select

See Also
static string getGMT(string $format, integer $timestamp)

A wrapper for get, this function will force the GMT timezone.

Parameters
  • $format stringA valid PHP date format

  • $timestamp integer(optional) A unix timestamp to format. Omitting this parameter will result in the current time being used

Returns

The formatted date in GMT

static array|string|null getSetting(string $name)

Accessor function for the settings of the DateTimeObj. Currently the available settings are time_format, date_format, datetime_format and datetime_separator. If $name is not provided, the entire $settings array is returned.

Returns

If $name is omitted this function returns array. If $name is not set, this fucntion returns null If $name is set, this function returns string

static string getTimeAgo(string $format)

A wrapper for get, this function will return a HTML string representing an <abbr> element which contained the formatted date of now, and an RFC 2822 formatted date (Thu, 21 Dec 2000 16:01:07 +0200) as the title attribute. Symphony uses this in it's status messages so that it can dynamically update how long ago the action took place using Javascript.

Parameters
  • $format stringA valid PHP date format

Returns

A HTML string of an <abbr> element with a class of 'timeago' and the current date (RFC 2822) as the title element. The value is the current time as specified by the $format.

Deprecated

This will be removed in the next version of Symphony

static array getTimeFormats()

Returns an array of the time formats Symphony supports. These formats are a combination of valid PHP format tokens.

See Also
static array getTimeFormatsSelectOptions(string $selected)

Returns an array of the time formats Symphony supports by applying the format to the current datetime. The array returned is for use with Widget::Select()

Parameters
  • $selected stringA preselected time format, defaults to null

Returns

An associative array, for use with Widget::Select

See Also
static array getTimezones(string $zone)

This functions acts as a standard way to get the timezones regardless of PHP version. It accepts a single parameter, zone, which returns the timezones associated with that 'zone'

Parameters
  • $zone stringThe zone for the timezones the field wants. This maps to the DateTimeZone constants

See Also
static array getTimezonesSelectOptions(string $selected)

Loads all available timezones using getTimezones() and builds an array where timezones are grouped by their region (Europe/America etc.) The options array that is returned is designed to be used with Widget::Select

Parameters
  • $selected stringA preselected timezone, defaults to null

Returns

An associative array, for use with Widget::Select

See Also
static array getZones()

This functions acts as a standard way to get the zones available on the system. For PHP5.2, these constants are just copied from PHP5.3

See Also
static DateTime|boolean parse(string $string)

Parses the given string and returns a DateTime object. Please note that for best compatibility with European dates it is recommended that your site be in a PHP5.3 environment.

Parameters
  • $string string(optional) A string containing date and time, defaults to the current date and time

Returns

The DateTime object, or if the date could not be parsed, false.

static void setDefaultTimezone(string $timezone)

Uses PHP's datedefaulttimezone_set function to set the system timezone. If the timezone provided is invalid, a E_USER_WARNING will be raised.

Parameters
  • $timezone stringA valid timezone identifier, such as UTC or Europe/Lisbon

See Also
static void setSettings(array $settings)

This function takes an array of settings for DateTimeObj to use when parsing input dates. The following settings are supported, time_format, date_format, datetime_separator and timezone. This equates to Symphony's default region group set in the Configuration class. If any of these values are not provided the class will fallback to existing self::$settings values

Parameters
  • $settings arrayAn associative array of formats for this class to use to format dates

static boolean validate(string $string)

Validate a given date and time string

Parameters
  • $string stringA date and time string or timestamp to validate

Returns

Returns true for valid dates, otherwise false

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details