Returns a DateTime instance for the given datetime

@param  mixed $datetime

@return DateTimeInterface
480422
public function getDatetimeObject($datetime = null)
    {
        if ($datetime instanceof DateTimeInterface) {
            return $datetime;
        }

        if (is_integer($datetime)) {
            $datetime = date('Y-m-d H:i:s', $datetime);
        }

        return new DateTime($datetime);
    }
1264964
protected function setTime($time) {

        if ($time === null) {
            $time = 0;
        }

        $this->time = new \DateTime('@' . $time);
        return $this;

    }
487403
private function validateTimezone(DateTime $dateTime)
    {
        $dateTime = Carbon::instance($dateTime);

        // Make sure we have the proper timezone. This is to prevent a developer accidentally removing more than they
        // expect to remove
        if ($dateTime->getTimezone()->getName() !== 'UTC') {
            throw new \InvalidArgumentException('Passed datetime is not in UTC timezone.');
        }

        return $dateTime;
    }
654199
public function buildDateTimeRawValue(\DateTime $dateTime = null) {
		if (null === $dateTime) return null;
		return DateUtils::formatDateTime($dateTime, SqliteDateTimeColumn::FORMAT_DATE_TIME);
	}
607869
protected function getDateTimeForDb(DateTimeInterface $dateTime): string
    {
        try {
            return Type::getType(Type::DATETIME)
                ->convertToDatabaseValue($dateTime, $this->getConnection()->getDatabasePlatform());
        } catch (DBALException $exception) {
            $message = 'DateTime conversion to database format failed.';
            throw new RepositoryException($message, 0, $exception);
        }
    }
293023
public function withDateTime(\DateTimeImmutable $dt): self
    {
        $obj = clone $this;
        $obj->_dateTime = $dt;
        return $obj;
    }
1228393
public function transform($dateTime): ?int
    {
        if (null === $dateTime) {
            return null;
        }

        if (!$dateTime instanceof \DateTimeInterface) {
            throw new TransformationFailedException('Expected a \DateTimeInterface.');
        }

        return $dateTime->getTimestamp();
    }
1372076
public static function shortDateTime($datetime)
    {
        if (self::isDateTime($datetime)) {
            $str = self::dateTimeToTimeStamp($datetime);
            $string = date("d.m.Y H:i", $str);
            return $string;
        } else {
            return '';
        }
    }
850734
public function formatTime($time)
    {
        if ($this->timeFormat === null || $this->timeFormat === false) {
            return $time;
        }

        $dateTime = new \DateTime($time);

        if ($this->timeFormat === true) {
            return $dateTime;
        }

        return $dateTime->format($this->timeFormat);
    }
1120273
public function getDateString(DateTime $time)
	{
		if ($this->getOption('type') === 'date')
		{
			return $time->format('Y-m-d');
		}
		else if ($this->getOption('type') === 'datetime')
		{
			return $time->format('Y-m-d H:i:s');
		}
		else
		{
			return $time->format('H:i:s');
		}
	}
646568
public function withHour(int $hour): DateTime
    {
        return new static(
            $this->date(),
            Time::create($hour, $this->minute(), $this->second()),
            $this->timezone()
        );
    }
85189
public static function createFromDateTime(DateTimeInterface $dateTime)
    {
        return static::create(Date::createFromDateTime($dateTime), TimeOfDay::createFromDateTime($dateTime));
    }
1205368
protected function getDateTime($dateTime)
    {
        if ($dateTime instanceof \DateTime) {
            return $dateTime;
        }

        if ((is_string($dateTime) && (int) $dateTime > 0) || is_numeric($dateTime)) {
            return (new \DateTime())->setTimestamp($dateTime);

        }

        throw new \common_Exception(__('A date has to be a Datetime or timestamp'));
    }
1306172
public static function fromNativeDateTime(\DateTime $date_time)
    {
        $date = Date::fromNativeDateTime($date_time);
        $time = Time::fromNativeDateTime($date_time);

        return new static($date, $time);
    }
853006
static function parserDateTime($dateTime)
    {
        if (!$dateTime instanceof \DateTime) $dateTime = static::createDateTimeClass($dateTime);
        $year = $dateTime->format('Y');
        $day = $dateTime->format('j');
        $month = $dateTime->format('n');
        $hour = $dateTime->format('H');
        $minute = $dateTime->format('i');
        $second = $dateTime->format('s');
        return [ $hour, $minute, $second, $month, $day, $year ];
    }
1195822
public static function get(UTCDateTime $date): DateTime
    {
        $date = $date->toDateTime();
        $date->setTimezone(new DateTimeZone(date_default_timezone_get()));

        return $date;
    }
1101973
public function getISO8601ForUser(\DateTime $datetime = null)
    {
        if ($datetime) {
            $datetime->setTimezone($this->userManager->getTimezone());
            return $datetime->format(\DateTime::ISO8601);
        }

        return null;
    }