You are here

public static function DateTimePlus::createFromTimestamp in Service Container 7

Same name and namespace in other branches
  1. 7.2 lib/Drupal/Component/Datetime/DateTimePlus.php \Drupal\Component\Datetime\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: @see __construct()

array $settings: @see __construct()

File

lib/Drupal/Component/Datetime/DateTimePlus.php, line 163
Contains \Drupal\Component\Datetime\DateTimePlus.

Class

DateTimePlus
Wraps DateTime().

Namespace

Drupal\Component\Datetime

Code

public static function createFromTimestamp($timestamp, $timezone = NULL, $settings = array()) {
  if (!is_numeric($timestamp)) {
    throw new \Exception('The timestamp must be numeric.');
  }
  $datetime = new static('', $timezone, $settings);
  $datetime
    ->setTimestamp($timestamp);
  return $datetime;
}