public function DateTimeNormalizer::normalize in Drupal 9
Same name and namespace in other branches
- 8 core/modules/serialization/src/Normalizer/DateTimeNormalizer.php \Drupal\serialization\Normalizer\DateTimeNormalizer::normalize()
1 call to DateTimeNormalizer::normalize()
- DateTimeIso8601Normalizer::normalize in core/
modules/ serialization/ src/ Normalizer/ DateTimeIso8601Normalizer.php
1 method overrides DateTimeNormalizer::normalize()
- DateTimeIso8601Normalizer::normalize in core/
modules/ serialization/ src/ Normalizer/ DateTimeIso8601Normalizer.php
File
- core/
modules/ serialization/ src/ Normalizer/ DateTimeNormalizer.php, line 57
Class
- DateTimeNormalizer
- Converts values for datetime objects to RFC3339 and from common formats.
Namespace
Drupal\serialization\NormalizerCode
public function normalize($datetime, $format = NULL, array $context = []) {
assert($datetime instanceof DateTimeInterface);
$drupal_date_time = $datetime
->getDateTime();
if ($drupal_date_time === NULL) {
return $drupal_date_time;
}
return $drupal_date_time
->setTimezone($this
->getNormalizationTimezone())
->format(\DateTime::RFC3339);
}