Skip to content

Instantly share code, notes, and snippets.

@ranmyfriend
Created June 4, 2018 12:08
Show Gist options
  • Save ranmyfriend/8eae167d41ece9583dc8393c7f589e65 to your computer and use it in GitHub Desktop.
Save ranmyfriend/8eae167d41ece9583dc8393c7f589e65 to your computer and use it in GitHub Desktop.
extension DateFormatter {
class func formatter(dateFormat: String = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
timeZone: TimeZone? = TimeZone(abbreviation: "UTC")) -> DateFormatter? {
if let timeZone = timeZone {
return self.init(dateFormat: dateFormat, timeZone: timeZone)
}
return nil
}
convenience init(dateFormat: String, timeZone: TimeZone) {
self.init()
self.dateFormat = dateFormat
self.timeZone = timeZone
}
}
guard let df = DateFormatter.formatter() else {return debugPrint(":( Invalid TimeZone")}
print(df.dateFormat)
print(df.timeZone)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment