timestamper.online
Back to Guides

How to Handle Unix Timestamps in Swift

Handle Unix time in Swift for iOS/macOS development.

1. Get Current Timestamp
swift
// Current timestamp (TimeInterval is double)
let now = Date().timeIntervalSince1970
2. Convert Date to Timestamp
swift
// Date to timestamp
let date = ISO8601DateFormatter().date(from: "2024-01-01T00:00:00Z")!
let ts = date.timeIntervalSince1970
3. Convert Timestamp to Readable Date
swift
// Timestamp to date
let date = Date(timeIntervalSince1970: 1704067200)

Need to convert a specific timestamp right now?

Use Online Converter