fm:DateFormat


When dealing with dates in your application, the default is usually too long, contains too much information, is ugly looking or just not what you want.
The system default is something like this: YYYY-MM-DD HH:MM:SS

The fm:DateFormat component allows you to (re)format a date returned by the system, in the same way php does.

This component cannot contain children.

Example 1 - the following example will print the media upload time in the following format: 26.04.2012

<fm:DateFormat date="{$media_upload}" format="d.m.Y" />

Supported attributes

NameRequiredDefaultDescription
dateRequiredN/AThe date to format. This attribute can accept many formats, such as YYYY-MM-DD, 'now', 'tomorrow'.
Note Bene:
While this parameter is required, the value passed can be left blank: so the parameter passed would be: ' date="" '
If the value passed is left out, the default will be the current date and time.
formatRequiredN/AHow to format the date. This attribute accepts a similar format as PHP's date() function
timezoneRequiredCanada/EasternSets the timezone of the date/time.
Please note: The time provided by this component may differ by 1 hour (form what is expected) for certain timezones because some parts of the world do not adhere to Daylight Savings Time.

Possible values for this attribute are
  • Kwajalein: -12.00 hours from Greenwich Mean Time
  • Pacific/Midway: -11.00 hours from Greenwich Mean Time
  • Pacific/Honolulu: -10.00 hours from Greenwich Mean Time
  • America/Anchorage: -9.00 hours from Greenwich Mean Time
  • America/Los_Angeles: -8.00 hours from Greenwich Mean Time
  • America/Denver: -7.00 hours from Greenwich Mean Time
  • America/Tegucigalpa: -6.00 hours from Greenwich Mean Time
  • Canada/Eastern: -5.00 hours from Greenwich Mean Time
  • America/Caracas: -4.30 hours from Greenwich Mean Time
  • America/Halifax: -4.00 hours from Greenwich Mean Time
  • America/St_Johns: -3.30 hours from Greenwich Mean Time
  • America/Argentina/Buenos_Aires: -3.00 hours from Greenwich Mean Time
  • America/Sao_Paulo: -3.00 hours from Greenwich Mean Time
  • Atlantic/South_Georgia: -2.00 hours from Greenwich Mean Time
  • Atlantic/Azores: -1.00 hours from Greenwich Mean Time
  • Europe/Dublin: 0 hours from Greenwich Mean Time
  • Europe/Belgrade: 1.00 hours from Greenwich Mean Time
  • Europe/Minsk: 2.00 hours from Greenwich Mean Time
  • Asia/Kuwait: 3.00 hours from Greenwich Mean Time
  • Asia/Tehran: 3.30 hours from Greenwich Mean Time
  • Asia/Muscat: 4.00 hours from Greenwich Mean Time
  • Asia/Yekaterinburg: 5.00 hours from Greenwich Mean Time
  • Asia/Kolkata: 5.30 hours from Greenwich Mean Time
  • Asia/Katmandu: 5.45 hours from Greenwich Mean Time
  • Asia/Dhaka: 6.00 hours from Greenwich Mean Time
  • Asia/Rangoon: 6.30 hours from Greenwich Mean Time
  • Asia/Krasnoyarsk: 7.00 hours from Greenwich Mean Time
  • Asia/Brunei: 8.00 hours from Greenwich Mean Time
  • Asia/Seoul: 9.00 hours from Greenwich Mean Time
  • Australia/Darwin: 9.30 hours from Greenwich Mean Time
  • Australia/Canberra: 10.00 hours from Greenwich Mean Time
  • Asia/Magadan: 11.00 hours from Greenwich Mean Time
  • Pacific/Fiji: 12.00 hours from Greenwich Mean Time
  • Pacific/Tongatapu: 13.00 hours from Greenwich Mean Time

Template variables

This component has no template variables. It only outputs one thing, which is the re-formatted date.



More Examples

Example 2

The following example will print the media upload time for timezone 'Canada/Eastern' in the following format: YYYY-MM-DD HH:MM:SS

<fm:DateFormat date="{$media_upload}" format="Y-m-d H:i:s" timezone="Canada/Eastern" />

Example 3

The following example will display the date/time "2012-10-01 11:03:35" for timeezone 'America/Los_Angeles' in the following format: YYYY-MM-DD HH:MM:SS

<fm:DateFormat date="2012-10-01 11:03:35" format="Y-m-d H:i:s" timezone="America/Los_Angeles" />

Example 4

The following example prints the current time, for timeezone 'America/Los_Angeles', in the following format: YYYY-MM-DD HH:MM:SS

<fm:DateFormat date="" format="Y-m-d H:i:s" timezone="America/Los_Angeles" />

See also