Skip to content

Instantly share code, notes, and snippets.

@fmaxx
Created October 5, 2018 06:45
Show Gist options
  • Save fmaxx/762a124bc033574cc9f776a18f1c8093 to your computer and use it in GitHub Desktop.
Save fmaxx/762a124bc033574cc9f776a18f1c8093 to your computer and use it in GitHub Desktop.
Date, utilities
extension Date {
public func toLabel(pattern: String = "HH:mm dd-MM-yy", locale: Locale = .current, abbreviation: String = "GMT") -> String {
let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone(abbreviation: abbreviation)
dateFormatter.locale = locale
dateFormatter.dateFormat = pattern
return dateFormatter.string(from: self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment