Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. TimeTrait.php

function TimeTrait::getDateTime

Returns a DateTimeInterface object representing the timestamp associated with the UUID

Return value

DateTimeImmutable A PHP DateTimeImmutable instance representing the timestamp of a time-based UUID

File

vendor/ramsey/uuid/src/Rfc4122/TimeTrait.php, line 40

Class

TimeTrait
Provides common functionality for getting the time from a time-based UUID

Namespace

Ramsey\Uuid\Rfc4122

Code

public function getDateTime() : DateTimeInterface {
    $time = $this->timeConverter
        ->convertTime($this->fields
        ->getTimestamp());
    try {
        return new DateTimeImmutable('@' . $time->getSeconds()
            ->toString() . '.' . str_pad($time->getMicroseconds()
            ->toString(), 6, '0', STR_PAD_LEFT));
    } catch (Throwable $e) {
        throw new DateTimeException($e->getMessage(), (int) $e->getCode(), $e);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal