eZ\Publish\Core\FieldType\DateAndTime\Value::fromTimestamp PHP Method

fromTimestamp() public static method

Creates a Value from the given $timestamp.
public static fromTimestamp ( integer $timestamp ) : Value
$timestamp integer
return Value
    public static function fromTimestamp($timestamp)
    {
        try {
            return new static(new DateTime("@{$timestamp}"));
        } catch (Exception $e) {
            throw new InvalidArgumentValue('$timestamp', $timestamp, __CLASS__, $e);
        }
    }

Usage Example

Example #1
0
 /**
  * Converts an $hash to the Value defined by the field type
  *
  * @param mixed $hash Null or associative array containing timestamp and optionally date in RFC850 format.
  *
  * @return \eZ\Publish\Core\FieldType\DateAndTime\Value $value
  */
 public function fromHash($hash)
 {
     if ($hash === null) {
         return $this->getEmptyValue();
     }
     if (isset($hash['rfc850']) && $hash['rfc850']) {
         return Value::fromString($hash['rfc850']);
     }
     return Value::fromTimestamp((int) $hash['timestamp']);
 }
All Usage Examples Of eZ\Publish\Core\FieldType\DateAndTime\Value::fromTimestamp