mediatekformation

DateTimeToStringTransformer extends BaseDateTimeTransformer
in package

Transforms between a date string and a DateTime object.

Tags
author

Bernhard Schussek bschussek@gmail.com

author

Florian Eckerstorfer florian@eckerstorfer.org

Table of Contents

$formats  : mixed
$inputTimezone  : mixed
$outputTimezone  : mixed
$generateFormat  : string
Format used for generating strings.
$parseFormat  : string
Format used for parsing strings.
__construct()  : mixed
Transforms a \DateTime instance to a string.
reverseTransform()  : DateTime|null
Transforms a date string in the configured timezone into a DateTime object.
transform()  : string
Transforms a DateTime object into a date string with the configured format and timezone.

Properties

$formats

protected static mixed $formats = [\IntlDateFormatter::NONE, \IntlDateFormatter::FULL, \IntlDateFormatter::LONG, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT]

$parseFormat

Format used for parsing strings.

private string $parseFormat

Different than the because formats for parsing support additional characters in PHP that are not supported for generating strings.

Methods

__construct()

Transforms a \DateTime instance to a string.

public __construct([string|null $inputTimezone = null ][, string|null $outputTimezone = null ][, string $format = 'Y-m-d H:i:s' ]) : mixed
Parameters
$inputTimezone : string|null = null

The name of the input timezone

$outputTimezone : string|null = null

The name of the output timezone

$format : string = 'Y-m-d H:i:s'

The date format

Tags
see
DateTime::format()

for supported formats

Return values
mixed

reverseTransform()

Transforms a date string in the configured timezone into a DateTime object.

public reverseTransform(string $value) : DateTime|null
Parameters
$value : string

A value as produced by PHP's date() function

Tags
throws
TransformationFailedException

If the given value is not a string, or could not be transformed

Return values
DateTime|null

An instance of \DateTime

transform()

Transforms a DateTime object into a date string with the configured format and timezone.

public transform(DateTimeInterface $dateTime) : string
Parameters
$dateTime : DateTimeInterface

A DateTimeInterface object

Tags
throws
TransformationFailedException

If the given value is not a \DateTimeInterface

Return values
string

A value as produced by PHP's date() function

Search results