# proto: google.protobuf.Timestamp: 秒值超出范围

- **ID:** `go/protobuf-timestamp-out-of-range`
- **领域:** go
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

构造的 google.protobuf.Timestamp 的秒值超出有效范围 [-62135596800, 253402300799]，通常来自零值 time.Time 或毫秒级的 Unix 时间戳。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.x | active | — | — |

## 解决方案

1. **** (93% 成功率)
   ```
   Use timestamppb.New(t) which converts time.Time correctly, and validate t.IsZero() before conversion; for unset use a nil *timestamppb.Timestamp instead of zero.
   ```
2. **** (90% 成功率)
   ```
   Convert from milliseconds explicitly: ts := timestamppb.New(time.UnixMilli(ms)) so the seconds/nanos split is correct.
   ```

## 无效尝试

- **** — Seconds must be in seconds; milliseconds overflow the valid range and produce an out-of-range error. (90% 失败率)
- **** — time.Time{}.Unix() is a large negative number that may fall outside the valid proto range depending on the year. (70% 失败率)
