Skip to content

Instantly share code, notes, and snippets.

@alexbosworth
Created March 20, 2015 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexbosworth/16624acfa817e401560e to your computer and use it in GitHub Desktop.
Save alexbosworth/16624acfa817e401560e to your computer and use it in GitHub Desktop.
Strip the minutes and seconds from a date, keeping yymmddhh
/** Strip minutes and seconds from a date
*/
func hourFloorFromDate(date: NSDate) -> NSDate? {
let calendar: NSCalendar
if let c = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian) { calendar = c } else { return nil }
let units = NSCalendarUnit.CalendarUnitYear | .CalendarUnitMonth | .CalendarUnitDay | .CalendarUnitHour
return calendar.dateFromComponents(calendar.components(units, fromDate: date))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment