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

# Kafka Connect TimestampConverter SMT Usage Reference for Confluent Platform

The `TimestampConverter` SMT (`org.apache.kafka.connect.transforms.TimestampConverter`)
converts record timestamps between various formats, including Unix epoch
integers, formatted strings, and Connect’s native Date or Timestamp types.

## Description

This SMT applies to an individual field 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.

For timestamp-based topic routing, see [Kafka Connect TimestampRouter SMT Usage Reference for Confluent Platform](timestamprouter.md#timestamprouter) and
[Kafka Connect MessageTimestampRouter SMT Usage Reference for Confluent Platform](messagetimestamprouter.md#messagetimestamprouter).

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

## Properties

| Name                        | Description                                                                                                                                                                                                | Type    | Default        | Valid values                                     | Importance   |
|-----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|----------------|--------------------------------------------------|--------------|
| `target.type`               | The target format for the converted timestamp.                                                                                                                                                             | string  |                | string, unix, Date, Time, Timestamp              | high         |
| `field`                     | The specific field name to convert. If left empty, the entire record value is treated as the timestamp.                                                                                                    | string  | “”             |                                                  | high         |
| `format`                    | The `java.text.SimpleDateFormat` pattern used to parse or generate string timestamps. For more 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. Converting values using microseconds or<br/>nanoseconds can cause precision loss.                 | string  | `milliseconds` | seconds, milliseconds, microseconds, nanoseconds | low          |
| `replace.null.with.default` | Specifies whether to replace null fields with their defined default<br/>values. When set to `true`, the default value is applied. Otherwise,<br/>the field remains null.                                   | boolean | `true`         | `true` or `false`                                | medium       |

## Examples

### Convert a Unix epoch to a date string

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"`

### Set the converter precision to microseconds

This configuration snippet shows how to use `TimestampConverter` to define the
converter precision to microseconds. Converting values using microseconds or
nanoseconds can cause precision loss.

```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`

## Predicates

Configure transformations with predicates to ensure they process only records
that satisfy a particular condition. You can also use predicates in a
transformation chain with the [Kafka Connect Filter (Kafka) SMT Usage Reference for Confluent Platform](filter-ak.md#ak-filter) to conditionally filter specific
records. For more information, see [Predicates](filter-ak.md#predicates).
