W3cubDocs

/Symfony 2.7

Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer

class DateTimeToTimestampTransformer extends BaseDateTimeTransformer

Transforms between a timestamp and a DateTime object

Methods

__construct(string $inputTimezone = null, string $outputTimezone = null)

Constructor.

from BaseDateTimeTransformer
int transform(DateTime $value)

Transforms a DateTime object into a timestamp in the configured timezone.

DateTime reverseTransform(string $value)

Transforms a timestamp in the configured timezone into a DateTime object

Details

public __construct(string $inputTimezone = null, string $outputTimezone = null)

Constructor.

Parameters

string $inputTimezone The name of the input timezone
string $outputTimezone The name of the output timezone

Exceptions

UnexpectedTypeException if a timezone is not a string
InvalidArgumentException if a timezone is not valid

public int transform(DateTime $value)

Transforms a DateTime object into a timestamp in the configured timezone.

Parameters

DateTime $value A \DateTime object

Return Value

int A timestamp

Exceptions

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

public DateTime reverseTransform(string $value)

Transforms a timestamp in the configured timezone into a DateTime object

Parameters

string $value A timestamp

Return Value

DateTime A \DateTime object

Exceptions

TransformationFailedException If the given value is not a timestamp or if the given timestamp is invalid.