Epoch & Unix Timestamp in Swift

Get the current epoch timestamp

let epochSeconds = Int(Date().timeIntervalSince1970)

Convert epoch to date

let date = Date(timeIntervalSince1970: 1718200000)

Convert date to epoch

let epoch = Int(ISO8601DateFormatter().date(from: "2026-06-12T00:00:00Z")!.timeIntervalSince1970)

Swift notes

timeIntervalSince1970 is a Double of seconds — multiply by 1000 for milliseconds. Date itself is timezone-less; zones only apply at formatting time.

Check any value live with the epoch converter, or read what Unix time actually counts.

Other languages

C · C# · C++ · Dart · Go · Java · JavaScript · Kotlin · MySQL · Perl · PHP · PostgreSQL · Python · R · Ruby · Rust · Scala · SQLite · TypeScript