src/ZonedDateTime.php
public static function fromDateTime(\DateTimeInterface $dateTime) : ZonedDateTime
    {
        $localDateTime = LocalDateTime::fromDateTime($dateTime);

        $dateTimeZone = $dateTime->getTimezone();

        if ($dateTimeZone === false) {
            throw new DateTimeException('This DateTime object has no timezone.');
        }

        $timeZone = TimeZone::fromDateTimeZone($dateTimeZone);

        if ($timeZone instanceof TimeZoneOffset) {
            $timeZoneOffset = $timeZone;
        } else {
            $timeZoneOffset = TimeZoneOffset::ofTotalSeconds($dateTime->getOffset());
        }

        $instant = Instant::of($dateTime->getTimestamp(), $localDateTime->getNano());

        return new ZonedDateTime($localDateTime, $timeZoneOffset, $timeZone, $instant);
    }
public static function fromDateTime(\DateTimeInterface $dateTime) : ZonedDateTime
    {
        $localDateTime = LocalDateTime::fromDateTime($dateTime);

        $dateTimeZone = $dateTime->getTimezone();

        if ($dateTimeZone === false) {
            throw new DateTimeException('This DateTime object has no timezone.');
        }

        $timeZone = TimeZone::fromDateTimeZone($dateTimeZone);

        if ($timeZone instanceof TimeZoneOffset) {
            $timeZoneOffset = $timeZone;
        } else {
            $timeZoneOffset = TimeZoneOffset::ofTotalSeconds($dateTime->getOffset());
        }

        $instant = Instant::of($dateTime->getTimestamp(), $localDateTime->getNano());

        return new ZonedDateTime($localDateTime, $timeZoneOffset, $timeZone, $instant);
    }
public static function fromDateTime ( \ DateTimeInterface $ dateTime ) : ZonedDateTime { $ localDateTime = LocalDateTime :: fromDateTime ( $ dateTime ) ; $ dateTimeZone = $ dateTime -> getTimezone ( ) ; if ( $ dateTimeZone === false ) { throw new DateTimeException ( 'This DateTime object has no timezone.' ) ; } $ timeZone = TimeZone :: fromDateTimeZone ( $ dateTimeZone ) ; if ( $ timeZone instanceof TimeZoneOffset ) { $ timeZoneOffset = $ timeZone ; } else { $ timeZoneOffset = TimeZoneOffset :: ofTotalSeconds ( $ dateTime -> getOffset ( ) ) ; } $ instant = Instant :: of ( $ dateTime -> getTimestamp ( ) , $ localDateTime -> getNano ( ) ) ; return new ZonedDateTime ( $ localDateTime , $ timeZoneOffset , $ timeZone , $ instant ) ; }
Creates a ZonedDateTime from a native DateTime or DateTimeImmutable object.

@param \DateTimeInterface $dateTime

@return ZonedDateTime

@throws DateTimeException If the DateTime object has no timezone.
Creates a ZonedDateTime from a native DateTime or DateTimeImmutable object .