Represents a Timestamp value.

Nanosecond precision is preserved by passing nanoseconds as a separate
argument to the constructor. If nanoseconds are given, any subsecond
precision in the timestamp will be overridden when encoding the timestamp
as a string.

Example:

use Google\Cloud\Core\Timestamp;

$timestamp = new Timestamp(new \DateTime('2003-02-05 11:15:02.421827Z'));
// Timestamps can be cast to strings.
echo (string) $timestamp;
CloneableInstantiable
Constants
public Google\Cloud\Core\Timestamp::FORMAT = 'Y-m-d\TH:i:s.u\Z'
public Google\Cloud\Core\Timestamp::FORMAT_INTERPOLATE = 'Y-m-d\TH:i:s.%\s\Z'
public Google\Cloud\Core\Timestamp::FORMAT_NO_MS = 'Y-m-d\TH:i:s\Z'
Methods
public __construct(DateTimeInterface $value, $nanoSeconds = NULL)
 


    public __toString()
     
    Format the value as a string.

    • return string
    • access private
    public formatAsString()
     
    Format the value as a string.

    Example:

    $value = $timestamp->formatAsString();
    
    • return string
    public formatForApi()
     
    Format a timestamp for the API with nanosecond precision.

    • return array
    public get()
     
    Get the underlying `\DateTimeInterface` implementation.

    Please note that if you provided nanoseconds when creating the timestamp,
    they will not be included in this value.

    Example:

    $dateTime = $timestamp->get();
    
    • return DateTimeInterface
    public nanoSeconds()
     
    Return the number of nanoseconds.

    Example:

    $nanos = $timestamp->nanoSeconds();
    
    • return int
    Properties
    private $nanoSeconds
     


    • var int
    private $value
     


    • var DateTimeInterface
    Methods
    private convertFractionToNanoSeconds( $subseconds)
     
    Convert subseconds, expressed as a decimal to nanoseconds.

    • return int
    private convertNanoSecondsToFraction( $nanos, $rpad = true)
     
    Convert nanoseconds to subseconds.

    Note that result should be used as a fraction of one second, but is
    given as an integer.

    • return string
    private createDateTimeFromSeconds( $seconds)
     
    Create a DateTimeImmutable instance from a UNIX timestamp (i.e. seconds since epoch).

    • return DateTimeImmutable
    private formatTimeAsArray(DateTimeInterface $dateTime, $ns)
     
    Format a timestamp for the API with nanosecond precision.

    • return array
    private formatTimeAsString(DateTimeInterface $dateTime, $ns)
     
    Create a Timestamp string in an API-compatible format.

    • return string
    private parseTimeString( $timestamp)
     
    Parse a Timestamp string and return a DateTimeImmutable instance and nanoseconds as an integer.

    • return array [\DateTimeImmutable, int]
    • throws Exception If the timestamp string is in an unrecognized format.
    © 2020 Bruce Wells
    Search Namespaces \ Classes
    ConfigurationNumbers (0-9.) only