Skip to content

Instantly share code, notes, and snippets.

@Lbatson
Created January 7, 2016 19:57
Show Gist options
  • Save Lbatson/99a68b525482bc81ba0d to your computer and use it in GitHub Desktop.
Save Lbatson/99a68b525482bc81ba0d to your computer and use it in GitHub Desktop.
func setTimeForDate (date: NSDate, hour: Int, minute: Int, second: Int) -> NSDate {
let unitFlags = [.Year, .Month, .Day, .Hour, .Minute, .Second] as NSCalendarUnit
// calendar here is NSCalendar.currentCalendar()
let dateComponents = calendar.components(unitFlags, fromDate: date)
dateComponents.hour = hour
dateComponents.minute = minute
dateComponents.second = second
let newDate = calendar.dateFromComponents(dateComponents)
print(newDate)
return newDate!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment