Convertools Dev
All tools

Unix Timestamp in Swift

Look up the current epoch time and convert between Unix seconds and UTC dates in Swift.

Get the current timestamp

import Foundation

print(Int(floor(Date().timeIntervalSince1970)))

Timestamp to date

import Foundation

print(ISO8601DateFormatter().string(from: Date(timeIntervalSince1970: 1_700_000_000)))

Date to timestamp

import Foundation

let formatter = ISO8601DateFormatter()
if let date = formatter.date(from: "2023-11-14T22:13:20Z") {
    print(Int(floor(date.timeIntervalSince1970)))
}

Open 1700000000 in the converter

Current Unix time

Seconds—
Milliseconds—
UTC
—
My time zone
—

Official reference ↗

Free to use. Your input stays in this browser.

How to use it

  1. Copy the current-time example into your Swift environment to read Unix seconds.
  2. Run the second example to display 1700000000 as a UTC date.
  3. Run the last example to convert that date back into seconds.

Foundation Date exposes Unix time as a Double measured in seconds. Floor the value before converting to an integer so fractional times before 1970 round correctly.