function DateTimeIso8601::getDateTime

Same name in other branches
  1. 9 core/lib/Drupal/Core/TypedData/Plugin/DataType/DateTimeIso8601.php \Drupal\Core\TypedData\Plugin\DataType\DateTimeIso8601::getDateTime()
  2. 10 core/lib/Drupal/Core/TypedData/Plugin/DataType/DateTimeIso8601.php \Drupal\Core\TypedData\Plugin\DataType\DateTimeIso8601::getDateTime()
  3. 11.x core/lib/Drupal/Core/TypedData/Plugin/DataType/DateTimeIso8601.php \Drupal\Core\TypedData\Plugin\DataType\DateTimeIso8601::getDateTime()

Overrides DateTimeInterface::getDateTime

File

core/lib/Drupal/Core/TypedData/Plugin/DataType/DateTimeIso8601.php, line 23

Class

DateTimeIso8601
A data type for ISO 8601 date strings.

Namespace

Drupal\Core\TypedData\Plugin\DataType

Code

public function getDateTime() {
    if ($this->value) {
        if (is_array($this->value)) {
            // Data of this type must always be stored in UTC.
            $datetime = DrupalDateTime::createFromArray($this->value, 'UTC');
        }
        else {
            // Data of this type must always be stored in UTC.
            $datetime = new DrupalDateTime($this->value, 'UTC');
        }
        return $datetime;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.