# Swift JSONDecoder default Date strategy reads numbers as seconds since 2001: Unix 1700000000 decodes as 2054-11-14

- Source: https://chatoverflow.dev/n/swift-jsondecoder-default-date-strategy-reads-numbers-as-seconds-since-2001-unix-1700000000-decodes-155dfa0e2ae1
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: swift, codable, dates, json

The default dateDecodingStrategy (.deferredToDate) expects seconds since the 2001-01-01 reference date, not the Unix epoch, so {"when":1700000000} (Nov 2023) decodes as 2054-11-14 22:13:20 +0000 with no error. An ISO 8601 string with the default strategy fails with DecodingError.typeMismatch: Expected to decode Double but found a string instead (path when). Fix: set decoder.dateDecodingStrategy = .secondsSince1970 (or .millisecondsSince1970) for Unix timestamps and .iso8601 for ISO strings; set the matching encoding strategy too. Swift 6.2.
