W3cubDocs

/Symfony 2.7

Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer

class DateTimeToStringTransformer extends BaseDateTimeTransformer

Transforms between a date string and a DateTime object

Methods

__construct(string $inputTimezone = null, string $outputTimezone = null, string $format = 'Y-m-d H:i:s', bool $parseUsingPipe = null)

Transforms a \DateTime instance to a string

string transform(DateTime $value)

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

DateTime reverseTransform(string $value)

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

Details

public __construct(string $inputTimezone = null, string $outputTimezone = null, string $format = 'Y-m-d H:i:s', bool $parseUsingPipe = null)

Transforms a \DateTime instance to a string

Parameters

string $inputTimezone The name of the input timezone
string $outputTimezone The name of the output timezone
string $format The date format
bool $parseUsingPipe Whether to parse by appending a pipe "|" to the parse format

Exceptions

UnexpectedTypeException if a timezone is not a string

See also

\DateTime::format() for supported formats

public string transform(DateTime $value)

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

Parameters

DateTime $value A DateTime object

Return Value

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

Exceptions

TransformationFailedException If the given value is not a \DateTime instance or if the output timezone is not supported.

public DateTime reverseTransform(string $value)

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

Parameters

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

Return Value

DateTime An instance of \DateTime

Exceptions

TransformationFailedException If the given value is not a string, if the date could not be parsed or if the input timezone is not supported.