Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexandre alexandre-g

  • Gold Coast
View GitHub Profile
@justinmfischer
justinmfischer / combineDateWithTime
Last active Dec 28, 2019
Combine date and time into a single NSDate in Swift 2.0
View combineDateWithTime
func combineDateWithTime(date: NSDate, time: NSDate) -> NSDate? {
let calendar = NSCalendar.currentCalendar()
let dateComponents = calendar.components([.Year, .Month, .Day], fromDate: date)
let timeComponents = calendar.components([.Hour, .Minute, .Second], fromDate: time)
let mergedComponments = NSDateComponents()
mergedComponments.year = dateComponents.year
mergedComponments.month = dateComponents.month
mergedComponments.day = dateComponents.day
You can’t perform that action at this time.