You are here

public static function Time::createFromDateTime in Time Field For Drupal 8.x / 9.x 2.x

Creates Time object from a DateTime object.

Parameters

\DateTime $date_time: The DateTime object to create the time for.

Return value

\Drupal\time_field\Time Time object created based upon the date time.

2 calls to Time::createFromDateTime()
Time::createFromTimestamp in src/Time.php
Creates Time object from timestamp.
TimeTest::testItCanBeCreatedByDateTime in tests/src/Unit/TimeTest.php
Test it can be created by a DateTime object.

File

src/Time.php, line 130

Class

Time
Time class represents time of day.

Namespace

Drupal\time_field

Code

public static function createFromDateTime(\DateTime $date_time) {
  return new static($date_time
    ->format('H'), $date_time
    ->format('i'), $date_time
    ->format('s'));
}