W3cubDocs

/Symfony 2.7

Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer

class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer

Transforms between a normalized time and a localized time string

Methods

__construct(string $inputTimezone = null, string $outputTimezone = null, int $dateFormat = null, int $timeFormat = null, int $calendar = \IntlDateFormatter::GREGORIAN, string $pattern = null)

Constructor.

string|array transform(DateTime $dateTime)

Transforms a normalized date into a localized date string/array.

DateTime reverseTransform(string|array $value)

Transforms a localized date string/array into a normalized date.

Details

public __construct(string $inputTimezone = null, string $outputTimezone = null, int $dateFormat = null, int $timeFormat = null, int $calendar = \IntlDateFormatter::GREGORIAN, string $pattern = null)

Constructor.

Parameters

string $inputTimezone The name of the input timezone
string $outputTimezone The name of the output timezone
int $dateFormat The date format
int $timeFormat The time format
int $calendar One of the \IntlDateFormatter calendar constants
string $pattern A pattern to pass to \IntlDateFormatter

Exceptions

UnexpectedTypeException If a format is not supported or if a timezone is not a string

See also

BaseDateTimeTransformer::formats for available format options

public string|array transform(DateTime $dateTime)

Transforms a normalized date into a localized date string/array.

Parameters

DateTime $dateTime Normalized date.

Return Value

string|array Localized date string/array.

Exceptions

TransformationFailedException If the given value is not an instance of \DateTime or if the date could not be transformed.

public DateTime reverseTransform(string|array $value)

Transforms a localized date string/array into a normalized date.

Parameters

string|array $value Localized date string/array

Return Value

DateTime Normalized date

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