Skip to content

Instantly share code, notes, and snippets.

@tsraveling
Created September 9, 2017 22:03
Show Gist options
  • Save tsraveling/42cafc58caa45c010ff941774555486b to your computer and use it in GitHub Desktop.
Save tsraveling/42cafc58caa45c010ff941774555486b to your computer and use it in GitHub Desktop.
Date Formatter
let globalDateFormatter : DateFormatter = {
let df = DateFormatter()
df.dateFormat = "MMMM d, yyyy"
return df
}()
extension Date {
static func fromString(_ source : String) -> Date? {
return globalDateFormatter.date(from: source)
}
func format() -> String {
return globalDateFormatter.string(from: self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment