Skip to content

Instantly share code, notes, and snippets.

@deathlezz
Last active July 23, 2021 10:58
Show Gist options
  • Save deathlezz/2030def398123e4cc6cbdca6a2f2dd75 to your computer and use it in GitHub Desktop.
Save deathlezz/2030def398123e4cc6cbdca6a2f2dd75 to your computer and use it in GitHub Desktop.
Check the current date in Swift 5.
//
// Check the current date
//
import Foundation
// Create current date
var currentDate = Date()
// Create a DateFormatter object
let format = DateFormatter()
// Set the timezone or choose the current (.current)
format.timeZone = TimeZone(abbreviation: "UTC+1")
// Set the format of our date
format.dateFormat = "yyyy-MM-dd HH:mm:ss Z"
// Set the current date, changed by timezone
let dateString = format.string(from: currentDate)
print(dateString) // 2021-07-21 14:01:39 +0100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment