You are here

public static function DateTimePlus::createFromDateTime in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Component/Datetime/DateTimePlus.php \Drupal\Component\Datetime\DateTimePlus::createFromDateTime()
  2. 9 core/lib/Drupal/Component/Datetime/DateTimePlus.php \Drupal\Component\Datetime\DateTimePlus::createFromDateTime()

Creates a date object from an input date object.

Parameters

\DateTime $datetime: A DateTime object.

array $settings: (optional) A keyed array for settings, suitable for passing on to __construct().

Return value

static A new DateTimePlus object.

1 call to DateTimePlus::createFromDateTime()
DateTimePlusTest::testDateTimezoneWithDateTimeObject in core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php
Tests DrupalDateTime with a datetime object.

File

core/lib/Drupal/Component/Datetime/DateTimePlus.php, line 138

Class

DateTimePlus
Wraps DateTime().

Namespace

Drupal\Component\Datetime

Code

public static function createFromDateTime(\DateTime $datetime, $settings = []) {
  return new static($datetime
    ->format(static::FORMAT), $datetime
    ->getTimezone(), $settings);
}