<a id="timestampconverter"></a>

# Kafka Connect TimestampConverter SMT Usage Reference for Confluent Cloud

The `org.apache.kafka.connect.transforms.TimestampConverter` Apache Kafka®
Single Message Transformation (SMT) converts timestamps between different
formats.

## Description

The `TimestampConverter` SMT converts timestamps between different formats such as Unix epoch, strings, and Date or Timestamp types. The transformation applies to individual fields or to the entire value.

Use the concrete transformation type designed for the record key (`org.apache.kafka.connect.transforms.TimestampConverter$Key`) or value (`org.apache.kafka.connect.transforms.TimestampConverter$Value`).

#### NOTE
The TimestampConverter SMT operates on one field at a time.

## Examples

This configuration snippet shows how to use `TimestampConverter` to transform
a Unix epoch (represented as an `int64` value) into a formatted date string.

```json
"transforms": "TimestampConverter",
"transforms.TimestampConverter.type": "org.apache.kafka.connect.transforms.TimestampConverter$Value",
"transforms.TimestampConverter.format": "yyyy-MM-dd",
"transforms.TimestampConverter.target.type": "string"
```

Before: `1696521093`

After: `"2023-10-05"`

This configuration snippet shows how to use `TimestampConverter` to define the
converter precision to microseconds. Precision loss occurs when you convert
values using microseconds or nanoseconds.

```json
"transforms.TimestampConverter.type": "org.apache.kafka.connect.transforms.TimestampConverter$Value",
"transforms.TimestampConverter.field": "event_date_long",
"transforms.TimestampConverter.unix.precision": "microseconds",
"transforms.TimestampConverter.target.type": "Timestamp"
```

Before: `1696521093`

After: `1696521093000000`

## Properties

| Name             | Description                                                                                                                                                                                                                                                                                                        | Type   | Default   | Valid Values                                               | Importance   |
|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------|-----------|------------------------------------------------------------|--------------|
| `target.type`    | The desired timestamp representation: string, unix, Date, Time, or Timestamp.                                                                                                                                                                                                                                      | String |           |                                                            | High         |
| `field`          | The field containing the timestamp, or empty if the entire value is a timestamp.                                                                                                                                                                                                                                   | String | “”        |                                                            | High         |
| `format`         | Format string for the timestamp that is compatible with `java.text.SimpleDateFormat`. Used to generate the output when type=string or used to parse the input if the input is a string. For additional details, see [SimpleDateFormat](https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html). | String | “”        |                                                            | Medium       |
| `unix.precision` | The desired Unix precision for the timestamp in seconds, milliseconds,<br/>microseconds, or nanoseconds. Precision loss occurs when you convert<br/>values using microseconds or nanoseconds.                                                                                                                      | String | “”        | Seconds, milliseconds (default), microseconds, nanoseconds | Low          |

## Predicates

Transformations can be configured with *predicates* so that the transformation
is applied only to records which satisfy a condition. You can use predicates in
a transformation chain and, when combined with the [Kafka Connect Filter (Kafka) SMT Usage Reference for Confluent Cloud](filter-ak.md#ak-filter), predicates
can conditionally filter out specific records. For details and examples, see [Predicates](filter-ak.md#predicates).
