public static function DateTimePlus::createFromTimestamp in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Component/Datetime/DateTimePlus.php \Drupal\Component\Datetime\DateTimePlus::createFromTimestamp()
- 9 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.
2 calls to DateTimePlus::createFromTimestamp()
- DateTimePlusTest::testTimestamp in core/
tests/ Drupal/ Tests/ Component/ Datetime/ DateTimePlusTest.php - Tests creating dates from timestamps, and manipulating timezones.
- EntitySerializationTest::testSerialize in core/
modules/ serialization/ tests/ src/ Kernel/ EntitySerializationTest.php - Tests entity serialization for core's formats by a registered Serializer.
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;
}