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

Breadcrumb

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

function DateTimePlus::createFromTimestamp

Creates a date object from timestamp input.

The timezone of a timestamp is always UTC. The timezone for a timestamp indicates the timezone used by the format() method.

Parameters

int $timestamp: A UNIX timestamp.

mixed $timezone: (optional) \DateTimeZone object, time zone string or NULL. See __construct() for more details.

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

Return value

static A new DateTimePlus object.

Throws

\InvalidArgumentException If the timestamp is not numeric.

File

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

Class

DateTimePlus
Wraps DateTime().

Namespace

Drupal\Component\Datetime

Code

public static function createFromTimestamp($timestamp, $timezone = NULL, $settings = []) {
    if (!is_numeric($timestamp)) {
        throw new \InvalidArgumentException('The timestamp must be numeric.');
    }
    $datetime = new static('', $timezone, $settings);
    $datetime->setTimestamp($timestamp);
    return $datetime;
}
RSS feed
Powered by Drupal