Last active
July 23, 2021 10:58
-
-
Save deathlezz/2030def398123e4cc6cbdca6a2f2dd75 to your computer and use it in GitHub Desktop.
Check the current date in Swift 5.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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