function DateTimePlus::createFromTimestamp
Same name in other branches
- 8.9.x core/lib/Drupal/Component/Datetime/DateTimePlus.php \Drupal\Component\Datetime\DateTimePlus::createFromTimestamp()
- 10 core/lib/Drupal/Component/Datetime/DateTimePlus.php \Drupal\Component\Datetime\DateTimePlus::createFromTimestamp()
- 11.x core/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: (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.
1 call to DateTimePlus::createFromTimestamp()
- DateTimePlusTest::testTimestamp in core/
tests/ Drupal/ Tests/ Component/ Datetime/ DateTimePlusTest.php - Tests creating dates from timestamps, and manipulating timezones.
File
-
core/
lib/ Drupal/ Component/ Datetime/ DateTimePlus.php, line 199
Class
- DateTimePlus
- Wraps DateTime().
Namespace
Drupal\Component\DatetimeCode
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.