Core/src/TimeTrait.php
private function formatTimeAsString(\DateTimeInterface $dateTime, $ns)
    {
        $dateTime = $dateTime->setTimeZone(new \DateTimeZone('UTC'));
        if ($ns === null) {
            return $dateTime->format(Timestamp::FORMAT);
        } else {
            $ns = (string) $ns;
            $ns = str_pad($ns, 9, '0', STR_PAD_LEFT);
            if (substr($ns, 6, 3) === '000') {
                $ns = substr($ns, 0, 6);
            }

            return sprintf(
                $dateTime->format(Timestamp::FORMAT_INTERPOLATE),
                $ns
            );
        }
    }
private function formatTimeAsString(\DateTimeInterface $dateTime, $ns)
    {
        $dateTime = $dateTime->setTimeZone(new \DateTimeZone('UTC'));
        if ($ns === null) {
            return $dateTime->format(Timestamp::FORMAT);
        } else {
            $ns = (string) $ns;
            $ns = str_pad($ns, 9, '0', STR_PAD_LEFT);
            if (substr($ns, 6, 3) === '000') {
                $ns = substr($ns, 0, 6);
            }

            return sprintf(
                $dateTime->format(Timestamp::FORMAT_INTERPOLATE),
                $ns
            );
        }
    }
private function formatTimeAsString ( \ DateTimeInterface $ dateTime , $ ns ) { $ dateTime = $ dateTime -> setTimeZone ( new \ DateTimeZone ( 'UTC' ) ) ; if ( $ ns === null ) { return $ dateTime -> format ( Timestamp :: FORMAT ) ; } else { $ ns = ( string ) $ ns ; $ ns = str_pad ( $ ns , 9 , '0' , STR_PAD_LEFT ) ; if ( substr ( $ ns , 6 , 3 ) === '000' ) { $ ns = substr ( $ ns , 0 , 6 ) ; } return sprintf ( $ dateTime -> format ( Timestamp :: FORMAT_INTERPOLATE ) , $ ns ) ; } }
Create a Timestamp string in an API-compatible format.

@param \DateTimeInterface $dateTime The date time object.
@param int|null $ns The number of nanoseconds. If null, subseconds from
$dateTime will be used instead.
@return string
Create a Timestamp string in an API - compatible format .