Google Cloud PHP shared dependency, providing functionality useful to all components. Client - Class Timestamp (1.69.0) (original) (raw)
Google Cloud PHP shared dependency, providing functionality useful to all components. Client - Class Timestamp (1.69.0)
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 ofDateTimeImmutable 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:
| Returns | |
|---|---|
| Type | Description |
| DateTimeInterface |
nanoSeconds
Return the number of nanoseconds.
Example:
| Returns | |
|---|---|
| Type | Description |
| int |
formatAsString
Format the value as a string.
Example:
| 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
FORMAT_INTERPOLATE
Value: 'Y-m-d\TH:i:s.%\s\Z'Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-06 UTC.