Created
June 4, 2018 12:08
-
-
Save ranmyfriend/8eae167d41ece9583dc8393c7f589e65 to your computer and use it in GitHub Desktop.
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
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