# 时间戳反序列化失败，因为纪元以毫秒为单位但预期是秒

- **ID:** `data/timestamp-epoch-millis-vs-seconds`
- **领域:** data
- **类别:** type_error
- **错误码:** `TIMESTAMP_EPOCH_UNIT_MISMATCH`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

数据源提供Unix纪元毫秒的时间戳（如1700000000000），但反序列化器期望秒（如1700000000），导致溢出或错误日期。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Apache Kafka 3.5.0 | active | — | — |
| Python datetime 3.11 | active | — | — |
| Java 17 | active | — | — |

## 解决方案

1. ```
   Detect the unit by checking the magnitude: if timestamp > 1e12, treat as milliseconds and divide by 1000. Example in Python: `if ts > 1e12: ts /= 1000`.
   ```
2. ```
   Configure the deserializer to expect milliseconds explicitly, e.g., in Kafka Connect: `timestamp.converter=org.apache.kafka.connect.json.JsonConverter` with `converter.type=timestamp` and `converter.format=epoch.millis`.
   ```

## 无效尝试

- **** — Dividing by 1000 in code may cause integer overflow if the timestamp is stored as a 32-bit integer. (70% 失败率)
- **** — Assuming all timestamps are in milliseconds may break when some sources use seconds. (80% 失败率)
