[+] Create function date.get() to get any date components from a date

This commit is contained in:
Hykilpikonna
2021-01-17 14:23:12 -05:00
parent c1e49ed66f
commit fd332ad9f4
+8
View File
@@ -45,4 +45,12 @@ extension Date
let comp = calendar.dateComponents([.hour, .minute, .second], from: self)
return (comp.hour!, comp.minute!, comp.second!)
}
/// Get another component
func get(_ c: Calendar.Component) -> Int
{
let calendar = Calendar.current
let comp = calendar.dateComponents([c], from: self)
return comp.value(for: c)!
}
}