Google Cloud PHP shared dependency, providing functionality useful to all components. Client - Class Timestamp (1.60.1)

Reference documentation and code samples for the Google Cloud PHP shared dependency, providing functionality useful to all components. Client class Timestamp.

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;

Namespace

Google \ Cloud \ Core

Methods

__construct

Parameters
Name Description
value DateTimeInterface

The timestamp value. Use of DateTimeImmutable is highly recommended over DateTime in order to avoid side effects.

nanoSeconds int

[optional] The number of nanoseconds in the timestamp. If omitted, subsecond precision will be obtained from the instance of \DateTimeInterface provided in the first argument. If provided, any precision in $value below seconds will be disregarded.

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();
Returns
Type Description
DateTimeInterface

nanoSeconds

Return the number of nanoseconds.

Example:

$nanos = $timestamp->nanoSeconds();
Returns
Type Description
int

formatAsString

Format the value as a string.

Example:

$value = $timestamp->formatAsString();
Returns
Type Description
string

__toString

Format the value as a string.

Returns
Type Description
string

formatForApi

Format a timestamp for the API with nanosecond precision.

Returns
Type Description
array

jsonSerialize

Implement JsonSerializable by returning a ISO 8601 formatted string

Returns
Type Description
string

Constants

FORMAT

Value: 'Y-m-d\TH:i:s.u\Z'

FORMAT_NO_MS

Value: 'Y-m-d\TH:i:s\Z'

FORMAT_INTERPOLATE

Value: 'Y-m-d\TH:i:s.%\s\Z'