DateTimeToStringTransformer
extends BaseDateTimeTransformer
in package
Transforms between a date string and a DateTime object.
Tags
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]
$inputTimezone
protected
mixed
$inputTimezone
$outputTimezone
protected
mixed
$outputTimezone
$generateFormat
Format used for generating strings.
private
string
$generateFormat
$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
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
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
Return values
string —A value as produced by PHP's date() function