how to get start and end time from datepicker in swift?

i want to get start and end time from date which i select from datepicker.

here is my code

  • UIDatePicker not displaying correctly
  • UIViewControllerHierarchyInconsistency crashes app only in iOS 8 and Xcode 6
  • iOS 7 UIDatePicker in UIAlertView customisation
  • UIControlEventEditingChanged doesn't get fired when using setText of UITextfield
  • UItableViewCell with UIDatePicker : month column gets covered
  • How to combine date and time from two UIDatePickers?
  •  func handleDatePicker(sender: UIDatePicker) {
            let dateFormatter = NSDateFormatter()
        dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss"
    
        let startOfDay = NSCalendar.currentCalendar().startOfDayForDate(sender.date)
    
        let components = NSDateComponents()
        components.hour   = 23
        components.minute = 59
        components.second = 59
        let endOfDay = NSCalendar.currentCalendar().dateByAddingComponents(components, toDate: startOfDay, options: NSCalendarOptions(rawValue: 0))
    }
    

    but i am getting output like 2016-10-12 12:00:00

    my question is how to get how to get output like this

    12-09-2016 00:00:00 AND 12-09-2016 23:59:59
    

    Solutions Collect From Internet About “how to get start and end time from datepicker in swift?”

    Try Below Code :-

            let calendar = NSCalendar(calendarIdentifier:NSCalendarIdentifierGregorian)
            calendar?.timeZone =  NSTimeZone(abbreviation: "GMT")!
            let startOfDay = calendar?.startOfDayForDate(sender.date)
    
            print("startDay \(startOfDay)")
            let components = NSDateComponents()
            components.hour   = 23
            components.minute = 59
            components.second = 59
            components.timeZone =  NSTimeZone(abbreviation: "GMT")
    
            let endOfDay = calendar?.dateByAddingComponents(components, toDate: startOfDay!, options: NSCalendarOptions(rawValue: 0))
            print("end Day \(endOfDay)")