Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eMdOS/ec207ac903792dd89102376c536f4adc to your computer and use it in GitHub Desktop.
Save eMdOS/ec207ac903792dd89102376c536f4adc to your computer and use it in GitHub Desktop.
// Swift 3
extension DateFormatter {
public static var iso8601: DateFormatter {
return DateFormatter.iso8601DateFormatter
}
private static let iso8601DateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
return formatter
}()
}
// Swift 2.2
extension NSDateFormatter {
public static var iso8601: NSDateFormatter {
return NSDateFormatter.iso8601DateFormatter
}
private static let iso8601DateFormatter: NSDateFormatter = {
let formatter = NSDateFormatter()
formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
return formatter
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment