Skip to content

Instantly share code, notes, and snippets.

@vialyx
Last active September 17, 2018 16:55
Show Gist options
  • Save vialyx/8f0b773c1474ecc7f7210a28d900f670 to your computer and use it in GitHub Desktop.
Save vialyx/8f0b773c1474ecc7f7210a28d900f670 to your computer and use it in GitHub Desktop.
extension Date {
func get(_ unit: Calendar.Component) -> Int {
return Calendar.current.component(unit, from: self)
}
var hour: Int {
return get(.hour)
}
}
let today = Date(timeIntervalSinceNow: 1 * 60 * 60) // Sep 17, 2018 at 8:55 PM
let hours = today.hour // 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment