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

1.72.2 (latest) 1.72.1 1.71.2 1.70.0 1.69.0 1.68.2 1.67.0 1.66.0 1.65.0 1.64.3 1.63.0 1.62.3 1.61.0 1.60.1 1.59.1 1.58.2 1.53.0 1.52.11 1.51.2 1.50.0 1.49.3 1.48.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'