You are here

public function Time::format in Time Field For Drupal 8.x / 9.x 8

Same name and namespace in other branches
  1. 2.x src/Time.php \Drupal\time_field\Time::format()

Format Time.

Parameters

string $format: Format string.

Return value

string Formatted time eg `12:30 AM`

File

src/Time.php, line 168

Class

Time
Time class represents time of day.

Namespace

Drupal\time_field

Code

public function format($format = 'h:i a') {
  $time = self::baseDateTime();
  $time
    ->setTimestamp($time
    ->getTimestamp() + $this
    ->getTimestamp());
  return $time
    ->format($format);
}