Skip to content

Instantly share code, notes, and snippets.

@anirudhamahale
Created April 3, 2018 11:46
Show Gist options
  • Save anirudhamahale/8f173065291d019e9d6f774d4f3737c0 to your computer and use it in GitHub Desktop.
Save anirudhamahale/8f173065291d019e9d6f774d4f3737c0 to your computer and use it in GitHub Desktop.
Compare Date
// Set date somewhere
UserDefaults.standard.set(Date(), forKey:"creationTime")
extension Date {
func isBeyond24Hours() -> Bool {
if let date = UserDefaults.standard.object(forKey: "creationTime") as? Date {
if let diff = Calendar.current.dateComponents([.hour], from: date, to: Date()).hour, diff > 24 {
return true
}
return false
}
return false
}
}
@anirudhamahale
Copy link
Author

List of formatters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment