format_datetime_to_timezone

Format datetime objects

Definition

string format_datetime_to_timezone(datetime $date, string $format, string $culture, string $timezone)

Converts $date to a formatted string based on $format, $culture and $timezone. The output time will be converted to the provided time zone, assuming that the time in $date is in UTC.

Parameters

datetime $date

A date to be formatted and converted to a different time zone.

string $format

Specifies the format in which to output the resulting date. Use custom date and time format strings, as implemented in .NET.

string $culture

Sets the date formatting to match the one used in the given culture. To define a culture tag, use a combination of language and region IANA tags.

string $timezone

The time zone to which the date is converted. Full names of Microsoft time zones and IANA time zones are supported, as well as some of the more common abbreviations.

Returns

string

The date formatted according to the parameters.

Examples

{
  "date": "2020-12-30T14:25:43+00:00"
}
{
  a: format_datetime_to_timezone(date, 'yyyy HH:mm', 'en-US', 'EST'),
  b: format_datetime_to_timezone(date, 'HH:mm', 'en-US', 'America/Cayman'),
  c: format_datetime_to_timezone(date, 'yy HH:mm', 'en-UK', 'CET'),
  d: format_datetime_to_timezone(date, 'HH:mm, dd/MMMM/yyyy', 'da-DK', 'Europe/Copenhagen'),  
  e: format_datetime_to_timezone(date, 'HH:mm, dd/M/yyyy', 'en-US', 'Eastern Standard Time'),
  f: format_datetime_to_timezone(date, 'yyyy HH:mm', 'en-US', 'Romance Standard Time')
}
{
  "a": "2020 09:25",
  "b": "09:25",
  "c": "20 15:25",
  "d": "15.25, 30.december.2020",
  "e": "09:25, 30/12/2020",
  "f": "2020 15:25"
}