src/ZonedDateTime.php
public static function ofInstant(Instant $instant, TimeZone $timeZone) : ZonedDateTime
    {
        $dateTimeZone = $timeZone->toDateTimeZone();

        // We need to pass a DateTimeZone to avoid a PHP warning...
        $dateTime = new \DateTime('@' . $instant->getEpochSecond(), $dateTimeZone);

        // ... but this DateTimeZone is ignored because of the timestamp, so we set it again.
        $dateTime->setTimezone($dateTimeZone);

        $localDateTime = LocalDateTime::parse($dateTime->format('Y-m-d\TH:i:s'));
        $localDateTime = $localDateTime->withNano($instant->getNano());

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

        return new ZonedDateTime($localDateTime, $timeZoneOffset, $timeZone, $instant);
    }
public static function ofInstant(Instant $instant, TimeZone $timeZone) : ZonedDateTime
    {
        $dateTimeZone = $timeZone->toDateTimeZone();

        // We need to pass a DateTimeZone to avoid a PHP warning...
        $dateTime = new \DateTime('@' . $instant->getEpochSecond(), $dateTimeZone);

        // ... but this DateTimeZone is ignored because of the timestamp, so we set it again.
        $dateTime->setTimezone($dateTimeZone);

        $localDateTime = LocalDateTime::parse($dateTime->format('Y-m-d\TH:i:s'));
        $localDateTime = $localDateTime->withNano($instant->getNano());

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

        return new ZonedDateTime($localDateTime, $timeZoneOffset, $timeZone, $instant);
    }
public static function ofInstant ( Instant $ instant , TimeZone $ timeZone ) : ZonedDateTime { $ dateTimeZone = $ timeZone -> toDateTimeZone ( ) ; // We need to pass a DateTimeZone to avoid a PHP warning... $ dateTime = new \ DateTime ( '@' . $ instant -> getEpochSecond ( ) , $ dateTimeZone ) ; // ... but this DateTimeZone is ignored because of the timestamp, so we set it again. $ dateTime -> setTimezone ( $ dateTimeZone ) ; $ localDateTime = LocalDateTime :: parse ( $ dateTime -> format ( 'Y-m-d\TH:i:s' ) ) ; $ localDateTime = $ localDateTime -> withNano ( $ instant -> getNano ( ) ) ; if ( $ timeZone instanceof TimeZoneOffset ) { $ timeZoneOffset = $ timeZone ; } else { $ timeZoneOffset = TimeZoneOffset :: ofTotalSeconds ( $ dateTime -> getOffset ( ) ) ; } return new ZonedDateTime ( $ localDateTime , $ timeZoneOffset , $ timeZone , $ instant ) ; }
Creates a ZonedDateTime from an instant and a time zone.

This resolves the instant to a date and time without ambiguity.

@param Instant  $instant  The instant.
@param TimeZone $timeZone The time zone.

@return ZonedDateTime
Creates a ZonedDateTime from an instant and a time zone .