Morilog\Jalali\jDateTime::createDateTime PHP Method

createDateTime() public static method

public static createDateTime ( $timestamp = null, null $timezone = null ) : DateTime | static
$timestamp
$timezone null
return DateTime | static
    public static function createDateTime($timestamp = null, $timezone = null)
    {
        $timezone = static::createTimeZone($timezone);
        if ($timestamp === null) {
            return Carbon::now($timezone);
        }
        if ($timestamp instanceof \DateTimeInterface) {
            return $timestamp;
        }
        if (is_string($timestamp)) {
            return new \DateTime($timestamp, $timezone);
        }
        if (is_numeric($timestamp)) {
            return Carbon::createFromTimestamp($timestamp, $timezone);
        }
        throw new \InvalidArgumentException('timestamp is not valid');
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @param string|null $str
  * @param null $timezone
  */
 public function __construct($str = null, $timezone = null)
 {
     $this->dateTime = jDateTime::createDateTime($str, $timezone);
 }